AppDomain.ExecuteAssembly()

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an application that displays a splash screen and loads another .NET
assembly using AppDomain.ExecuteAssembly.

I Create a new application domain then call ExecuteAssembly.

It works file, until I exit the application. Then I get an error when the
first application tries to exit:

An unhandled exception of type 'System.NullReferenceException' occurred in
system.drawing.dll

Additional information: Object reference not set to an instance of an object.

If I call AppDomain Unload in the dispose, sometimes it exits okay,
sometimes it doesn't obviously there is some timing issue.

Does anyone have an example where an application calls ExecuteAssembly() and
then waits for that assembly to exit, and then exit itself.
 
Colin said:
I have an application that displays a splash screen and loads another
.NET assembly using AppDomain.ExecuteAssembly.

I Create a new application domain then call ExecuteAssembly.

Splash screen? Does it have a UI? How do you create the message pump?

Usually you do this through a call to Application.Run which creates the
message pump. Typical code passes a Form to Run, which actually wraps the
Form in an ApplicationContext. ApplicationContext is a 'bridge' between the
message pump and the form. The problem is that the .NET Form and Win32
window are two different entities, they have different lifetime. Further,
the user expects the lifetime of the application process (the .NET thread
determines this) to be the same as the Win32 window.

ApplicationContext does this. Through this class, the pump will continue
until it is told to die and then it will dispose all forms created on the
thread. Then the pump will die and if this is the main thread then the
process will die too. OTOH the main form's HandleDestroy event generates the
message that will tell the message pump to die, and this happens when the
window closes. So closing the window will break the message pump, which will
allow the form to dispose its objects and then the main thread will die and
so will the process.
It works file, until I exit the application. Then I get an error
when the first application tries to exit:

An unhandled exception of type 'System.NullReferenceException'
occurred in system.drawing.dll

I wonder if there is a conflict between ApplicationContext and your shutdown
code.

Richard
 
Back
Top