My application is frezzing

Jun 24, 2009 at 2:03 PM

Hi all

I have a C# windows application, when it is become idle, it freeze, this happen from time to time.

I get the dump file, but I was unable to analyze it using WinDbg.

 

I got this stack log file using Managed Stack Explorer.

 

Any Help appreciated.


23/06/2009 12:33:20 PM
Stack trace depth is set to show all frames

Thread ID: 2700
 0.  (Source Unavailable)
 1.  (Source Unavailable)
 2. System.ComponentModel.BackgroundWorker.OnDoWork (Source Unavailable)
 3. System.ComponentModel.BackgroundWorker.WorkerThreadStart (Source Unavailable)
 4. System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage (Source Unavailable)
 5. System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage (Source Unavailable)
 6. System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.DoAsyncCall (Source Unavailable)
 7. System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack (Source Unavailable)
 8. System.Threading._ThreadPoolWaitCallback.WaitCallback_Context (Source Unavailable)
 9. System.Threading.ExecutionContext.Run (Source Unavailable)
 10. System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal (Source Unavailable)
 11. System.Threading._ThreadPoolWaitCallback.PerformWaitCallback (Source Unavailable)

 

 

23/06/2009 12:33:02 PM
Stack trace depth is set to show all frames

Thread ID: 4008
 0. DevComponents.DotNetBar.?.? (Source Unavailable)
 1. System.Threading.ThreadHelper.ThreadStart_Context (Source Unavailable)
 2. System.Threading.ExecutionContext.Run (Source Unavailable)
 3. System.Threading.ThreadHelper.ThreadStart (Source Unavailable)

 

23/06/2009 12:32:44 PM
Stack trace depth is set to show all frames

Thread ID: 620
 0. System.Threading.WaitHandle.WaitAny (Source Unavailable)
 1. System.Net.TimerThread.ThreadProc (Source Unavailable)
 2. System.Threading.ThreadHelper.ThreadStart_Context (Source Unavailable)
 3. System.Threading.ExecutionContext.Run (Source Unavailable)
 4. System.Threading.ThreadHelper.ThreadStart (Source Unavailable)

 

23/06/2009 12:32:25 PM
Stack trace depth is set to show all frames

Thread ID: 2004
 0. [Internal thisFrame, 'M-->U', System.Net.UnsafeNclNativeMethods.SafeNetHandles::accept] (Source Unavailable)
 1. System.Net.SafeCloseSocket.InnerSafeCloseSocket.Accept (Source Unavailable)
 2. System.Net.Sockets.Socket.Accept (Source Unavailable)
 3. System.Net.Sockets.TcpListener.AcceptSocket (Source Unavailable)
 4. System.Runtime.Remoting.Channels.Http.HttpServerChannel.Listen (Source Unavailable)
 5. System.Threading.ThreadHelper.ThreadStart_Context (Source Unavailable)
 6. System.Threading.ExecutionContext.Run (Source Unavailable)
 7. System.Threading.ThreadHelper.ThreadStart (Source Unavailable)

 

23/06/2009 12:32:08 PM
Stack trace depth is set to show all frames

Thread ID: 592
 0.  (Source Unavailable)
 1.  (Source Unavailable)
 2. System.ComponentModel.BackgroundWorker.OnDoWork (Source Unavailable)
 3. System.ComponentModel.BackgroundWorker.WorkerThreadStart (Source Unavailable)
 4. System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage (Source Unavailable)
 5. System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage (Source Unavailable)
 6. System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.DoAsyncCall (Source Unavailable)
 7. System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack (Source Unavailable)
 8. System.Threading._ThreadPoolWaitCallback.WaitCallback_Context (Source Unavailable)
 9. System.Threading.ExecutionContext.Run (Source Unavailable)
 10. System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal (Source Unavailable)
 11. System.Threading._ThreadPoolWaitCallback.PerformWaitCallback (Source Unavailable)

 

23/06/2009 12:31:53 PM
Stack trace depth is set to show all frames

Thread ID: 316
 0. System.Threading.WaitHandle.WaitOne (Source Unavailable)
 1. System.Threading.WaitHandle.WaitOne (Source Unavailable)
 2. System.Windows.Forms.Control.WaitForWaitHandle (Source Unavailable)
 3. System.Windows.Forms.Control.MarshaledInvoke (Source Unavailable)
 4. System.Windows.Forms.Control.Invoke (Source Unavailable)
 5.  (Source Unavailable)
 6.  (Source Unavailable)
 7. System.Threading.ThreadHelper.ThreadStart_Context (Source Unavailable)
 8. System.Threading.ExecutionContext.Run (Source Unavailable)
 9. System.Threading.ThreadHelper.ThreadStart (Source Unavailable)

 


23/06/2009 12:30:58 PM
Stack trace depth is set to show all frames

Thread ID: 3888
 0. System.Threading.WaitHandle.WaitOne (Source Unavailable)
 1. System.Threading.WaitHandle.WaitOne (Source Unavailable)
 2. System.Windows.Forms.Control.WaitForWaitHandle (Source Unavailable)
 3. System.Windows.Forms.Control.MarshaledInvoke (Source Unavailable)
 4. System.Windows.Forms.Control.Invoke (Source Unavailable)
 5. System.Windows.Forms.WindowsFormsSynchronizationContext.Send (Source Unavailable)
 6. Microsoft.Win32.SystemEvents.SystemEventInvokeInfo.Invoke (Source Unavailable)
 7. Microsoft.Win32.SystemEvents.RaiseEvent (Source Unavailable)
 8. Microsoft.Win32.SystemEvents.OnUserPreferenceChanged (Source Unavailable)
 9. Microsoft.Win32.SystemEvents.WindowProc (Source Unavailable)
 10. [Internal thisFrame, 'M-->U', System.Windows.Forms.UnsafeNativeMethods::DispatchMessageW] (Source Unavailable)
 11. System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop (Source Unavailable)
 12. System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (Source Unavailable)
 13. System.Windows.Forms.Application.ThreadContext.RunMessageLoop (Source Unavailable)
 14. System.Windows.Forms.Application.DoEvents (Source Unavailable)
 15. DevComponents.DotNetBar.PanelEx.OnSystemColorsChanged (Source Unavailable)
 16. System.Windows.Forms.Control.OnSystemColorsChanged (Source Unavailable)
 17. DevComponents.DotNetBar.PanelEx.OnSystemColorsChanged (Source Unavailable)
 18. System.Windows.Forms.Control.OnSystemColorsChanged (Source Unavailable)
 19. System.Windows.Forms.Control.UserPreferenceChanged (Source Unavailable)
 20. System.RuntimeMethodHandle.InvokeMethodFast (Source Unavailable)
 21. System.Reflection.RuntimeMethodInfo.Invoke (Source Unavailable)
 22. System.Delegate.DynamicInvokeImpl (Source Unavailable)
 23. Microsoft.Win32.SystemEvents.SystemEventInvokeInfo.InvokeCallback (Source Unavailable)
 24. System.RuntimeMethodHandle.InvokeMethodFast (Source Unavailable)
 25. System.Reflection.RuntimeMethodInfo.Invoke (Source Unavailable)
 26. System.Delegate.DynamicInvokeImpl (Source Unavailable)
 27. System.Windows.Forms.Control.InvokeMarshaledCallbackDo (Source Unavailable)
 28. System.Windows.Forms.Control.InvokeMarshaledCallbackHelper (Source Unavailable)
 29. System.Windows.Forms.Control.InvokeMarshaledCallback (Source Unavailable)
 30. System.Windows.Forms.Control.InvokeMarshaledCallbacks (Source Unavailable)
 31. System.Windows.Forms.Control.MarshaledInvoke (Source Unavailable)
 32. System.Windows.Forms.Control.Invoke (Source Unavailable)
 33. System.Windows.Forms.WindowsFormsSynchronizationContext.Send (Source Unavailable)
 34. Microsoft.Win32.SystemEvents.SystemEventInvokeInfo.Invoke (Source Unavailable)
 35. Microsoft.Win32.SystemEvents.RaiseEvent (Source Unavailable)
 36. Microsoft.Win32.SystemEvents.OnUserPreferenceChanged (Source Unavailable)
 37. Microsoft.Win32.SystemEvents.WindowProc (Source Unavailable)
 38. [Internal thisFrame, 'M-->U', System.Windows.Forms.UnsafeNativeMethods::DispatchMessageW] (Source Unavailable)
 39. System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop (Source Unavailable)
 40. System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (Source Unavailable)
 41. System.Windows.Forms.Application.ThreadContext.RunMessageLoop (Source Unavailable)
 42. System.Windows.Forms.Application.RunDialog (Source Unavailable)
 43. System.Windows.Forms.Form.ShowDialog (Source Unavailable)
 44.  (Source Unavailable)
 45. System.Windows.Forms.MenuItem.OnClick (Source Unavailable)
 46. System.Windows.Forms.MenuItem.MenuItemData.Execute (Source Unavailable)
 47. System.Windows.Forms.Command.Invoke (Source Unavailable)
 48. System.Windows.Forms.Command.DispatchID (Source Unavailable)
 49. System.Windows.Forms.Control.WmCommand (Source Unavailable)
 50. System.Windows.Forms.Control.WndProc (Source Unavailable)
 51. System.Windows.Forms.ScrollableControl.WndProc (Source Unavailable)
 52. System.Windows.Forms.Control.ControlNativeWindow.OnMessage (Source Unavailable)
 53. System.Windows.Forms.Control.ControlNativeWindow.WndProc (Source Unavailable)
 54. System.Windows.Forms.NativeWindow.Callback (Source Unavailable)
 55. [Internal thisFrame, 'M-->U', System.Windows.Forms.UnsafeNativeMethods::DispatchMessageW] (Source Unavailable)
 56. System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop (Source Unavailable)
 57. System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (Source Unavailable)
 58. System.Windows.Forms.Application.ThreadContext.RunMessageLoop (Source Unavailable)
 59. System.Windows.Forms.Application.Run (Source Unavailable)
 60.  (Source Unavailable)
 61. System.RuntimeMethodHandle.InvokeMethodFast (Source Unavailable)
 62. System.Reflection.RuntimeMethodInfo.Invoke (Source Unavailable)
 63. System.Reflection.RuntimeMethodInfo.Invoke (Source Unavailable)
 64. System.Reflection.MethodBase.Invoke (Source Unavailable)
 65.  (Source Unavailable)
 66.  (Source Unavailable)
 67.  (Source Unavailable)
 68. System.RuntimeMethodHandle.InvokeMethodFast (Source Unavailable)
 69. System.Reflection.RuntimeMethodInfo.Invoke (Source Unavailable)
 70. System.Reflection.RuntimeMethodInfo.Invoke (Source Unavailable)
 71. System.Reflection.MethodBase.Invoke (Source Unavailable)

 

 


23/06/2009 12:34:35 PM
Stack trace depth is set to show all frames

Thread ID: 1076
 0. [Internal thisFrame, 'M-->U', System.Net.UnsafeNclNativeMethods.SafeNetHandles::accept] (Source Unavailable)
 1. System.Net.SafeCloseSocket.InnerSafeCloseSocket.Accept (Source Unavailable)
 2. System.Net.Sockets.Socket.Accept (Source Unavailable)
 3. System.Net.Sockets.TcpListener.AcceptSocket (Source Unavailable)
 4. System.Runtime.Remoting.Channels.Http.HttpServerChannel.Listen (Source Unavailable)
 5. System.Threading.ThreadHelper.ThreadStart_Context (Source Unavailable)
 6. System.Threading.ExecutionContext.Run (Source Unavailable)
 7. System.Threading.ThreadHelper.ThreadStart (Source Unavailable)

Jun 24, 2009 at 2:43 PM

Some code could help us out.

There are lots of reasons why an application would freeze. Infinite loop is one, hogging the CPU without using Sleep or DoEvents,

One place to start is to post you code of :

1) DoWork

2) WorkerCompleted.

3) How you call this worker

Jun 24, 2009 at 3:55 PM

Frezzing happen when the allpications is idle, I mean there is no activity. But still my application connectiong to a remote object which is hosted by a service.

here i am waiting to get any message from a service, add it to the queue, then dequeue it and execute it.

here is DoWork code:

 

private  System.Collections.Queue  serverToClient;


this.serverToClient = System.Collections.Queue.Synchronized(new System.Collections.Queue()); // threadsafe queue.
<font size="2" color="#0000ff"><font size="2" color="#0000ff">

this

</font></font>
<font size="2" color="#0000ff">

 

</font>

.backgroundWorker.RunWorkerAsync();

.
.

public void CallbackSink_OnHostToClient(SQRemoteTypes.CommsInfo info)
{
     this.serverToClient.Enqueue(info.Message);
}

internal void ChildWantToUpdateEvents(string msg)
{
        this.serverToClient.Enqueue(msg);
}

private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
          BackgroundWorker worker = sender as BackgroundWorker;
          this.StartServing( worker, e);
}

private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
                this.ExcuteServerMessage(e.UserState.ToString());
}

private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
           if (e.Error != null)
                      MessageBoxEx.Show(new Form() { TopMost = true }, e.Error.Message);

            else if (e.Cancelled)
            {
           }
          else
         {
          }
}

private void StartServing( BackgroundWorker worker, DoWorkEventArgs e)
{
           string msg = null;
           while (!this.isClosing)
           {
                   if (this.serverToClient.Count > 0)
                  {
                       try
                       {
                               msg = this.serverToClient.Dequeue().ToString();
                              worker.ReportProgress(0, msg as object);
                        }
                        catch (Exception ex)
                      {
                               Console.WriteLine("StartServing : " + ex.Message);
                        }
              }
               else
                           Thread.Sleep(100);
               }
}

private void ExcuteServerMessage(string info)
{
string[] command = info.Split('|');
switch (command[0])
{
           case "1":
                          //do some work here
                             break;
               case "2":
                                //do some work here                                   
                                break;
                case "3":
                               //do some work here
                             break;
             }
}


        private void StopBackgroundWorker()
        {
            if (this.backgroundWorker.IsBusy)
                this.backgroundWorker.CancelAsync();
            this.backgroundWorker.DoWork -= new DoWorkEventHandler(backgroundWorker_DoWork);
            this.backgroundWorker.RunWorkerCompleted -= new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);
            this.backgroundWorker.ProgressChanged -= new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
            this.backgroundWorker.Dispose();
        }



        private void InitializeBackgoundWorker()
        {
            this.backgroundWorker = new System.ComponentModel.BackgroundWorker();
            this.backgroundWorker.WorkerReportsProgress = true;
            this.backgroundWorker.WorkerSupportsCancellation = true;

            backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
            backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);
            backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
        }
Jun 24, 2009 at 5:33 PM

As suspected,

Thread.Sleep(100) gets executed in every itteration once the servertoclient queue is empty or "idle".

As you know, the Sleep will try to relinquish contol to pending threads. Do you have any pending threads?

Are you updating controls on a form from a different thread!?

Put a break point on the Sleep and stepinto to know where does it take you.

 

 

Jun 24, 2009 at 6:14 PM

Thread.Sleep(100) gets executed in every itteration once the servertoclient queue is empty or "idle".

that's true.

As you know, the Sleep will try to relinquish contol to pending threads. Do you have any pending threads?

No, there is no any other thread, just the main thread and the backgroundWorker  thread.

Are you updating controls on a form from a different thread!?

Yes, backgroundWorker will update some controls in the switch statment.

Put a break point on the Sleep and stepinto to know where does it take you.

It did'nt take me to any other place, just countinue looping.

Jun 24, 2009 at 7:41 PM

2 things you can try.

1) Add a DoEvents() before Sleep(100). This will help proces any pending messages in the windows message queue.

2) Make sure if you are updating controls from a different thread to use the InvokeRequired, but in this case there is no crash, so I am dissmissing this case.

Need to see more code on what you are doing the case statement.

More likely its number 1.

 

 

 

 

Jun 24, 2009 at 8:06 PM

1) Add a DoEvents() before Sleep(100). This will help proces any pending messages in the windows message queue.

Added (see ExcuteServerMessage).

2) Make sure if you are updating controls from a different thread to use the InvokeRequired, but in this case there is no crash, so I am dissmissing this case.

implemented

Need to see more code on what you are doing the case statement.

More likely its number 1.

private void ExcuteServerMessage(string info)
        {
            if (this.InvokeRequired)
            {
                try
                {
                    this.Invoke(new ExcuteServerMessageDlg(ExcuteServerMessage), new object [] {info});
                }
                catch (Exception ex)
                {
                    Util.Logging.WriteToLogFile(string.Concat(ex.Message, ", ExcuteServerMessage"));
                }
            }
            else
            {
                string[] command = info.Split('|');
                switch (command[0])
                {
                    case ONE:// Write Operation.
                        this.InsertWirteOperation(command);
                        break;
                    case "2":// Read Operation.
                        this.InsertReadOperation(command);
                        break;
                    case "3":// Delete Read or Write Operation from the Queue Event Entry.
                        this.DeleteReadOrWriteEntryFromQueueEvents(command);
                        break;
                    case "5":// Update Read, Write cache and Queue total count.
                        this.UpdateReadWriteCacheAndQueueCount(command);
                        break;
                    case "6":// Update Write Cache.
                        this.UpdateWriteCache(command);
                        break;
                    case "7":// Update Read Cache.
                        this.UpdateReadCache(command);
                        break;
                    case "8": // Create Balloon.
                        this.CreatBalloon(command);
                        break;
                    case "9": // Media formatted.
                        this.MediaIsFormmated(command);
                        break;
                    case "10":
                        this.buttonFileDisconnect_Click(this.btnFileDisconnect, null);
                        this.Refresh();
                        break;
                    case "11": // Media is Full
                        this.UpdateDiscIcon(command);
                        break;
                    case "13":// Queue is Paused now. you can import, erase, ... 
                        this.SendMsgToChildForm(command);
                        break;
                    case "14":
                        this.AddEventViewerInfo(info);
                        break;
                    case "15": // set initial value for writing progress bar
                        this.InitializeFileProgressbar(command);
                        break;
                    case "16": // set writing progress value
                        this.UpdateFileProgressbar(command);
                        break;
                    case "17":
                        this.queueItems = command[1];
                        this.explorerBarGroupItem1.Text = string.Format(QueueTotal, this.queueItems);
                        this.explorerBarGroupItem1.Refresh();
                        break;
                }
            }
        }
            
        // Write Operation.
        // command = "1|FileName|FileId|Queue.Count"
        private void InsertWirteOperation(string[] command)
        {
            System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] {
                                (++counter).ToString (),
                                "Write",
                                command[1]}, -1, System.Drawing.Color.Green, System.Drawing.Color.White, null);
            listViewItem1.Name = command[2];
            this.listViewFileQueue.Items.Insert(0, listViewItem1);
            this.queueItems = command[3];
            this.explorerBarGroupItem1.Text = string.Format(QueueTotal, this.queueItems);
            this.explorerBarGroupItem1.Refresh();
            this.listViewFileQueue.Update();
            this.listViewFileQueue.Refresh();
        }
others cases are doing similar job.

Jun 29, 2009 at 3:21 PM

If the application is managed then you need to run the sos extension commands and point windbg to your pdb files (Windbg | File | Symbol Files).  The help within Windbg lists all the sos extension commands.

Coordinator
Jun 29, 2009 at 3:30 PM

Hi khayralla, I would strongly recommend not cross-posting (posting the exact same post in multiple places).  There is also some help on the other post you did, but seems like you're getting much better help here.  Just a thought for the next time.

Jun 29, 2009 at 3:49 PM

In regards to your code StartServing should look more like this rather than doing busy waiting you are context switching every .1 (sleep(100)) seconds and wasting cycles<font size="2">

System.Threading.

</font>

ManualResetEvent shutdown = new System.Threading.ManualResetEvent(false);<font size="2">

System.Threading.

</font>

AutoResetEvent newQueueItem = new System.Threading.AutoResetEvent(false);<font size="2">

 

</font>

while (0 != System.Threading.WaitHandle.WaitAny(new System.Threading.WaitHandle[]{shutdown, newQueueItem}))

{<font size="2">

 

</font>

try

 

{

<font size="2">

msg =

</font>

this.serverToClient.Dequeue().ToString();<font size="2">

worker.ReportProgress(0, msg

</font>

as object);

}

<font size="2">

 

</font>

 

 

 

catch (Exception ex)

{<font size="2">

       Util.Logging.WriteToLogFile(

</font>

 

       string.Concat(ex.Message, ", StartServing"));

}

<font size="2">

}

</font>

 

 

 

Jun 29, 2009 at 4:49 PM

thanks sweetbox

for StartServing , I would like to make things simple at the beginning, then I can implement your suggestion.

freezing is happened on different machines, I will read about sos command.