BackgroundWorker

Posted by dragon on Saturday, 10 September 2011

type='html'>

BackgroundWorker Class

Executes an operation on a separate thread.

Sample Code

1.Create event DoWork.

Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
'Sample how to disable button send before send email method after that enabled button.
DisableSendButton()
' to do SendEmail method
EnabledSendButton()

End Sub

2. Show how to invoke method when use BackgroundWorker control.

Private Sub DisableSendButton()
If Me.InvokeRequired Then
Me.Invoke(New MethodInvoker(DisableSendButton))
Else
btnSend.Enabled = False
btnCancelSend.Visible = True
End If
End Sub

Private Sub EnabledSendButton()
If Me.InvokeRequired Then
Me.Invoke(New MethodInvoker(EnabledSendButton))
Else
btnSend.Enabled = True
btnCancelSend.Visible = False
End If
End Sub

3.Start BackgroundWorker

BackgroundWorker1.RunWorkerAsync()

{ 0 comments... read them below or add one }

Post a Comment