I have a simple "working" form that works in its thread to inform the user that the application has not died during long operations. To get the working form for the update, I had to insert a call to DoEvents() .
I am curious if this will be just pump messages for the current thread I'm working on, or will it do this for the entire application? I would prefer the main window to remain immune until the operation is completed, so I'm curious how this happens. Below is the code for the work form.
Just to be clear, I'm fine with the code I have, but I would like to know how DoEvents() behaves with threads.
Public Class frmWorking ''' <summary> ''' Creates and starts a new thread to handle the Working Dialog ''' </summary> ''' <returns>The thread of the Working dialog.</returns> ''' <remarks></remarks> Public Shared Function StartWait() As WorkingFromToken Dim th As New Threading.Thread(AddressOf ShowWait) Dim token As New WorkingFromToken th.Start(token) Return token End Function Private Shared Sub ShowWait(token As WorkingFromToken) Dim frm As New frmWorking Try frm.Show() Do If frm.txtWait.Text.Length > 45 Then frm.txtWait.Text = "Working" Else frm.txtWait.Text &= "." End If Windows.Forms.Application.DoEvents() Threading.Thread.Sleep(250) Loop While token.Running frm.Hide() Catch ex As Threading.ThreadAbortException Threading.Thread.ResetAbort() frm.Hide() Return End Try End Sub End Class
source share