.net 2.0 WinForms Application suspends for 6 min at startup
Hi fellows,
currently I do have a very strange problem with getting a .net 2.0 application to run smoothly.
Used OS: Windows 2003 (1.0/1.1/2.0/3.0), Windows 2000 (1.0/1.1/2.0)
The Project has been converted from a 1.1 WinForms project to 2.0 by Visual Studio.
After compiling the project and all dependencies I start the executable. There is some activity on CPU and memory for about 30 seconds (loading static data). After that the whole application becomes totally unresponsive; the application main window (which already raised the "Load" event) is only an empty rectangle on the screen. The application stays in that state for about 5 to 7 minutes and then recovers and shows the mainform. Code-wise there's nothing left to come after the "Load" event and this one runs through.
When I run the application in debug mode from Visual Studio 2005 it starts up within seconds. Same happens when I run the application and attach the debugger. No blocking.
So a debugging step-through won't get me further. :(
Anyone got an idea?
- what could cause this to happen problem
- how can I find the problem (waiting for a resource)
- how can I solve the problem
If necessary I could provide additional information.
Thanks for any help, Frank
Thanks very much for your hint, in the meantime I came to that idea myself as well ;)
The application hangs at
MANWinApp.Run(new MainForm())
where the Run() Method consists of the following code
{
mainForm.Load += MANSplashDialog.CloseEventHandler;
Current.mainForm = mainForm;
Application.Run(mainForm);
}
The splash screen (which is a System.Windows.Forms.Form itself) calls itself up in a separate background thread, again with Application.Run(splashscreeninstance). My gut feeling tells me that this is not really right (to run an Application again in another one on a separate thread). Somehow in .Net 1.1 works fine. It is implemented like that in about 6 different .net 1.1 applications. (And I am the poor guy to analyse the porting to 2.0 now. :()
Can you (or someone else) advise me briefly (got a code snippet) about how to do it right. "It" means showing a splash screen while some initialisation is done for the main application?
Thanks a lot in advance
Frank
This is actually a tough problem. There have been some solutions posted on Code Project and elsewhere on how to do it. The problem is with the application context. The application context (Application creates one) is hooked to the form you create. When the form is closed the thread (and hence your app) closes. I've seen some solutions where the main form is created, it creates a splash form and then hides itself while loading. I've also seen solutions where people play with the application context by switching forms and whatnot. None of them really work well. Nevertheless they might provide you some insight.
Another option is to look at VB which supports a splash screen through a checkbox option. It uses a custom application object to start the splashscreen on a secondary thread and then loads the main form on the primary thread. You can probably simply reuse this base class by loading the Microsoft.VisualBasic assembly. I'm not sure it'll work but it might.
Michael Taylor - 11/7/06
Hello guys,
thanks very much for your hints. I will start to examine a few examples from CodeProject and try to see if I can steal^^reuse something ;)
What kind of bugs me about the problem is: It works fine with .Net 1.1 and under 2.0 the application manages to recover, but only after 5 to 7 minutes (so what is the runtime waiting for during this period?), and running it from the Visual Studio just does not close the splash form but activates the actual main form.
Any further ideas are appreciated. :)
Have a nice time, Frank