none
How to determine a UI thread is blocked? RRS feed

  • Question

  • Hi,

    I am using C# in VS2005 to work with Kodak SVT Twain driver in a document scanner.
    As my program is working in multiple threads mode, I use delegate to update UI control on a main form. (I search many web pages that any update to UI control must be done on its UI own thread.

    However, I found that when the scanner is going to stop (all papers are scanned) and the UI update on the main form is suspended until a Twain driver call returns.

    So I need to determine how to determine which part stops the update on the main form.

    (On the main form, it displays the images being scanned)

    Does anyone provide any good ways to determine it?

    I already try synchronous and asynchronous ways (InvokeRequired and Invoke) to do that but the UI update is still hold.

    Please help!

    THanks,
    Raymond
    Tuesday, May 22, 2007 4:57 PM

Answers

  • Hit Debug + Break All in the IDE, then Debug + Windows + Threads.  Right-click a thread in the list and choose Switch to Thread.  Inspect the call stack.  With some luck, you'll find the blocking driver call.

    If that driver is implemented as an ActiveX component, it is not unlikely that COM automatically marshaled a call you made on a background thread to the UI thread.  If that call then blocked, you have a dead UI thread.  Control.Invoke() will indead stall, waiting for the UI thread to unblock, giving you a potential deadlock.  Trying BeginInvoke() to prevent this is worth a shot...
    Tuesday, May 22, 2007 7:59 PM
    Moderator

All replies

  • I think you can use the System.Diagnostics.Process.Responding property to check this. To get the current process just use the Process.GetCurrentProcess method.
    Tuesday, May 22, 2007 7:26 PM
  • Hit Debug + Break All in the IDE, then Debug + Windows + Threads.  Right-click a thread in the list and choose Switch to Thread.  Inspect the call stack.  With some luck, you'll find the blocking driver call.

    If that driver is implemented as an ActiveX component, it is not unlikely that COM automatically marshaled a call you made on a background thread to the UI thread.  If that call then blocked, you have a dead UI thread.  Control.Invoke() will indead stall, waiting for the UI thread to unblock, giving you a potential deadlock.  Trying BeginInvoke() to prevent this is worth a shot...
    Tuesday, May 22, 2007 7:59 PM
    Moderator
  • But is it possible to check the status of UI thread/message queue in coding?

    Regards,
    Raymond
    Friday, May 25, 2007 10:18 AM
  • No.  The GetQueueStatus() API function can tell you how many messages are as yet unprocessed which would be a fairly reliable way to tell if the UI thread is pumping messages.  Problem is, you'd have to Invoke() that call.  Chicken-and-egg there, too bad they didn't design that function so you could pass a thread ID.
    Friday, May 25, 2007 10:36 AM
    Moderator