Thanks for the replies,
I don’t think anyone answered my original question, so I borrowed a technique I’ve used on other libraries before to launch a few windows. Hopefully there isn’t something I’m missing that will bite me later.
public static class Program
{
private static BlockingCollection<Game1> _games = new BlockingCollection<Game1>();
private static AutoResetEvent _stayAlive = new AutoResetEvent(false);
[STAThread]
static void Main()
{
SpawnWindow();
SpawnWindow();
// Keep the main UI thread alive until we decide we are done.
_stayAlive.WaitOne();
}
static void SpawnWindow()
{
Task.Factory.StartNew(() =>
{
using (var game = new Game1())
{
_games.Add(game);
game.Exiting += HandleGameExiting;
game.Run();
}
});
}
private static void HandleGameExiting(object sender, EventArgs e)
{
var game = sender as Game1;
if (game != null)
{
Game1 gameToRemove;
_games.TryTake(out gameToRemove);
if(gameToRemove == null)
{
Console.WriteLine("Failed to remove closing game.");
return;
}
// If no more windows exist lets close everything down.
if (_games.Count == 0)
_stayAlive.Set();
}
}
}