المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Thread.Join() and GUI



C# Programming
09-08-2010, 02:30 PM
Hi everyone,

I have a question about how to handle Thread.Join() and the cases where the thread is updating using Invoke.

The problem is my background thread calls back into a method periodically that uses Invoke() to update some GUI elements. Now, when I call Join() on my background thread (in response to the user cancelling the job and the application waiting for the thread to finish), the whole application hangs as the subsequent Invoke() calls never return because Join() is blocking the caller thread (i.e. my main thread).

Does anyone know how I can get around this? Thread.Sleep() is no use either as I do want the main thread to be responsive and at least handle these UI events. I was under the impression that the message pump was supposed to be active when using Thread.Join()
Cheers,
Pankaj