I made a launcher for my game and successfully found the code to launch the game. But for some reason it doesn't work. The error message is InvalidOperationException

Is there an easier way to do this? Or how can I fix this?

This is the code:

private void Startgame_Click(object sender, EventArgs e)
{
   using (Zombie_Shooter.GameCode game = new Zombie_Shooter.GameCode())
   {
       game.Run();
   }
}
有帮助吗?

解决方案

Do you can try this ?

Thread thread = new Thread(() =>
{    
     Game1 game = new Game();    
     game.Run();
});


private void Startgame_Click(object sender, EventArgs e)
{
   thread.Start();
   thread.Join();
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top