views:

44

answers:

1

I have one EXE (built in .Net) running on windows. When it runs, it'd get another EXE from server and execute under that same process. Using Process.Start I can execute the server EXE after dowloading but that'd start a new process with an extra step of downloading the EXE residing on the server. But I wanted a better solution.

A: 

If the downloaded executable is a .NET application, see AppDomain.ExecuteAssembly.

  1. Do not use a second appdomain. Just use AppDomain.Current.ExecuteAssembly.
  2. Do not call any WinForm functions before launching the second application. For example, don't create any windows.

If you need to create windows, create them after the executed application is running by attaching an event handler to the Application.Idle event. When the app is loaded and starts the WinForms message loop, this event will be raised. Here you can create windows or access the application's windows via Form.OpenForms.

Dark Falcon
It gives error in Main() SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application.
Joy
You can't run a winforms app in a secondary appdomain. There is no good solution for this.
Hans Passant
I found one solution here (http://www.codeproject.com/KB/cs/LoadExeIntoAssembly.aspx) but I could not get this working.
Joy
Thanks Dark, it worked.
Joy