.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

[1328 byte] By [FrankF?rster] at [2007-12-26]
# 1

As soon as the app blocks either attach to it through the debugger or use Process Explorer (www.sysinternals.com) to view the call stack to see what is going on. Trying creating an simple app and see if the problem occurs again.

Michael Taylor - 11/7/06

TaylorMichaelL at 2007-9-4 > top of Msdn Tech,.NET Development,Common Language Runtime...
# 2
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

FrankF?rster at 2007-9-4 > top of Msdn Tech,.NET Development,Common Language Runtime...
# 3

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

TaylorMichaelL at 2007-9-4 > top of Msdn Tech,.NET Development,Common Language Runtime...
# 4
The VB application framework also uses Application.Run(Form) to display the splash screen in a thread.
nobugz at 2007-9-4 > top of Msdn Tech,.NET Development,Common Language Runtime...
# 5

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

FrankF?rster at 2007-9-4 > top of Msdn Tech,.NET Development,Common Language Runtime...
# 6
Hi Frank,

Windows.Forms should just be following directions giving to it by Windows messages. Your debugger break has shown that your app is indeed busy pumping messages and is either idle or engaged processing a message deep inside the framework. To find out if it is a message causing the hang, add logging to your app's main form. Something like this:

Public Class Form1
Private mLog As IO.StreamWriter
Public Sub New()
InitializeComponent()
mLog = New IO.StreamWriter("c:\appmsg.log")
End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Dim tick As Integer = Environment.TickCount
MyBase.WndProc(m)
If Not mLog Is Nothing Then mLog.WriteLine("{0} took {1} msec", m, Environment.TickCount - tick)
End Sub
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
mLog.WriteLine("Closed event")
mLog.Close()
mLog = Nothing
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mLog.WriteLine("Load event")
End Sub
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
mLog.WriteLine("Shown event")
End Sub
End Class

Let us know what you see...

nobugz at 2007-9-4 > top of Msdn Tech,.NET Development,Common Language Runtime...

.NET Development

Site Classified