The problem is: you don't know what you want. This call to
Thread.Join()
is blocking, so the caller code is supposed to "freeze"; this is the essence of the concept of "waiting". Don't call this method. In this case, you are not waiting for the thread to be terminated, but you cannot want to wait and not to wait at the same time.
It's likely that you want something different. Of course, you don't want the UI to freeze. But what would you possibly want then? Of course, not "waiting". Probably, you want to notify the UI thread that the thread
child
is finished and do something in UI on this notification, for example, enable some disable buttons. Then do exactly that.
You mentioned that the thread is being aborted. Then you can handle
ThreadAbortException
send a notification in the handler. This is done by calling
Control.Invoke
with some delegate instance. This code can be executed in any thread, and is intended to be used in a non-UI thread. This call will post the data needed to invoke a delegate instance to the UI thread event queue, so the delegate instance will ultimately be invoked in the UI thread. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.invoke%28v=vs.110%29.aspx[
^].
Sometime, it is unsuitable to send such notification in the thread being terminate, because it can happen in different ways, and so on. You only need the capture the moment of time when the thread execution is stopped, by whatever reason, which is not what you care about. Then the possible approach is this: you can create 3rd thread which waits for your thread to be terminated and then, after the wait, it notifies the UI.
—SA