Hadi
Hadi

Reputation: 29

Debug WPF Project as process inside a WinForm solution

I have a C# solution with multiple WinFrom projects, and in this solution, I have a WPF project also. When I start a WinForm project as a process inside MainProject, it runs perfect and I can debug it without any problem. But when I want to start WPF project as a separate process inside MainProject, I can't debug it. I use Child Process Debugging Extension for debug child processes. My code for start child process :

            Process.Start(new ProcessStartInfo()
            {
                FileName = System.Reflection.Assembly.GetAssembly(typeof(UI.Export.DTO.Launcher)).Location,
                WorkingDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(UI.Export.DTO.Launcher)).Location),
                Arguments = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(launcher))),
            });

I also add both WinForm and WPF projects to Child Process Debugging Settings!

Thanks in advance :)

Upvotes: 2

Views: 91

Answers (1)

Rekshino
Rekshino

Reputation: 7325

I would

  • subscribe an Application.Startup
  • put a blocker to the event handler of Application.Startup
  • do attach to the process, while wpf application is hanging in the blocker part.


public partial class YourWpfApp : Application
{
    public YourWpfApp()
    {
        Startup += YourWpfApp_Startup;
    }

    private void YourWpfApp_Startup(object sender, StartupEventArgs e)
    {
        System.Threading.Thread.Sleep(50000);//Attach to the process, while waiting here.
        Startup -= YourWpfApp_Startup;
    }
}

Upvotes: 1

Related Questions