0

I'm writing a game editor and a game within C#. There are two applications: the game editor is a Winforms/SFML hybrid, and the game itself is a Windows application just running a simple game loop in SFML with a pretty standard Program.cs.

From within the editor, I'd like to be able to launch the game executable to playtest the changes. Preferably the effect would be similar to having started both applications from within Visual Studio via the usual multiple startup projects method.

Now, I'm guessing there are a few options here:

  • Launch Program.cs in some sort of a background thread. I don't want to do this because I'd prefer process isolation.
  • Launch the executable via a path with Process.Start(). I'm not sure if this gives the same level of debugging support as usual. I've not played with the debug mode call on Process enough to know if this is what I'm looking for or not.
  • Some other simple method I'm just not aware of?

What's the standard procedure to do this sort of thing?

Edit: I have been requested to explain how this is not a duplicate of Attach debugger in C# to another process I saw this question previously and still posted because that one focused on generically debugging any application. I have something much more specialized here because I control both apps directly; additionally the approach chosen here does not rely on interop as some of the answers there did.

Community
  • 1
  • 1
J Trana
  • 2,150
  • 2
  • 20
  • 32
  • It's not clear to me how this is different than the the "Launch Program.cs in some sort of background thread." Can you help clarify? – J Trana Jan 07 '17 at 22:25
  • In your solution, put the 2 projects (game_editor and game_itself). In game_editor references, add the game_itself executable. Create in the Game_Itself some public entry point allowing to run the game and call it from a background thread of the Game_Editor. You will then be "almost" isolated. – Graffito Jan 07 '17 at 22:28
  • 1
    As @Graffito writes, but load the other assembly, the game in this case, in another appdomain. Then it is still running in the same process but is isolated by default and if you ever want, you can easily add communication (function calls) across the appdomains. – thehennyy Jan 07 '17 at 22:31
  • Have you tried option 2 using VS attach debugger? This is what I have done in the past in similar scenarios. Keep in mind though that you might have problems debugging it from the start. – WozzeC Jan 07 '17 at 22:32
  • Possible duplicate of [Attach debugger in C# to another process](http://stackoverflow.com/questions/11811856/attach-debugger-in-c-sharp-to-another-process) – John Smith Jan 07 '17 at 22:47
  • @thehennyy I like that approach - it's not quite a separate process but a separate AppDomain is fine by me! Thanks! – J Trana Jan 07 '17 at 23:01

1 Answers1

0

@thehennyy had a good suggestion. I'm choosing an AppDomain as the level of isolation here as an acceptable compromise.

Here's the solution:

        var playtestDomain = AppDomain.CreateDomain("playtest");
        var assemblyPath = typeof(actual_game.Program).Assembly.Location;
        playtestDomain.ExecuteAssembly(assemblyPath);
J Trana
  • 2,150
  • 2
  • 20
  • 32