slowly I'm overworked...
I have a huge application with threading, timers, invoke (not BeginInvoke, so it is synchronous) and Application.DoEvents.
It is too much to post here and I don't know where the problem really is.
Every Method of mine is inside a try catch. Every catch is logged.
If I start my application from Visual Studio (F5) or while profiling it via Ants there is no Problem. The Application runs since some days. But as soon as I start the same debug version via windows explorer it freezes every few hours. It freezes without any exception or so. If I attach visual studio to this application and break it, it stops on Application.Run(new Form1());
I'm really confused and have no idea to repair it.
It is a .net 3.5 winforms application
It looks like one thread hangs here:
if (grabber.InvokeRequired)
{
Console.WriteLine("grabber.InvokeRequired");
this.Invoke((MethodInvoker) delegate { grabber.Navigate("http://www.google.de"); }); // <-- hang
}
else
{
grabber.Navigate(ig.StartUrl);
}
this snippet is part of an timer event
_timeout = new System.Timers.Timer(10000);
_timeout.Elapsed += new ElapsedEventHandler(OnWatchDogBark);
Edit
A sample for DoEvents(). This is in a lock() and in an invoke
grabber.DocumentCompleted -= grabber_DocumentCompleted;
grabber.Navigate("http://www.google.de");
while (grabber.ReadyState != WebBrowserReadyState.Complete)
{
timeout--;
Application.DoEvents();
Thread.Sleep(200);
if (timeout < 0)
{
timeout = 50;
grabber.Navigate("http://www.google.de");
}
}
Currently I use the System.Windows.Forms.Timer and some locks but there is no improvement.
Okay I used WinDbg to get some informations
!threads
PreEmptive GC Alloc Lock
ID OSID ThreadOBJ State GC Context Domain Count APT Exception
0 1 37ec 007cab18 6020 Enabled 00000000:00000000 007c8510 0 STA System.ArgumentException (02762ba8)
2 2 85b8 007d7c38 b220 Enabled 00000000:00000000 007c8510 0 MTA (Finalizer)
XXXX 3 0 06e9f548 9820 Enabled 00000000:00000000 007c8510 0 Ukn
21 5 3464 0d6dc598 200b020 Enabled 28cb5820:28cb5fe8 007c8510 0 MTA
22 6 62b0 0d6db9e0 200b220 Enabled 00000000:00000000 007c8510 0 MTA
23 7 8e58 0d6db5f8 80a220 Enabled 00000000:00000000 007c8510 0 MTA (Threadpool Completion Port)
XXXX 4 0 06f62d40 1801820 Enabled 00000000:00000000 007c8510 0 Ukn (Threadpool Worker)
XXXX f 0 132a3290 1801820 Enabled 00000000:00000000 007c8510 0 Ukn (Threadpool Worker)
XXXX 10 0 132a3678 1801820 Enabled 00000000:00000000 007c8510 0 Ukn (Threadpool Worker)
XXXX e 0 132a26d8 1801820 Enabled 00000000:00000000 007c8510 0 Ukn (Threadpool Worker)
XXXX 9 0 0d6db210 1801820 Enabled 00000000:00000000 007c8510 0 Ukn (Threadpool Worker)
!dlk
Examining SyncBlocks...
Scanning for ReaderWriterLock instances...
Scanning for holders of ReaderWriterLock locks...
Scanning for ReaderWriterLockSlim instances...
Scanning for holders of ReaderWriterLockSlim locks...
Examining CriticalSections...
Could not find symbol ntdll!RtlCriticalSectionList.
No deadlocks detected.
Could be a possible Deadlock in a background thread. Try looking at other threads that could block your app.
Toolbar -> Debug -> Windows -> Threads
http://msdn.microsoft.com/en-us/library/w15yf86f.aspx
There should be multiple threads and if you double click one you see the line where it is stopping your app.
And if you this line in your code:
Control.CheckForIllegalCrossThreadCalls = false;
Set it to true again. A possible cause for dead locks are background thread accessing controls.
Instead of writing this from a backgroud threads.
button1.Text = "hello"
write this.
this.Invoke(() => button1.Text = "hello");
If it's freezing, you are likely looking at a deadlock. One of the best ways I have found to find a deadlock is to use a crash dump and sosex.
Here's a good article on using this technique (it's asp.net, but the same principles apply): http://blogs.msdn.com/b/tess/archive/2010/04/27/debugging-a-classic-readerwriterlock-deadlock-with-sosex-dll.aspx
let the app run until it freezes, and take a hang dump: http://blogs.msdn.com/b/tess/archive/2006/10/16/net-hang-debugging-walkthrough.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With