Public Class Form1
Private Sub btnaceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaceptar.Click
If Not bgw1.IsBusy = True Then
bgw1.RunWorkerAsync()
End If
End Sub
Private Sub btncancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancelar.Click
If bgw1.WorkerSupportsCancellation = True Then
bgw1.CancelAsync()
End If
End Sub
Private Sub bgw1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgw1.DoWork
While True
If bgw1.CancellationPending = True Then
e.Cancel = True
Exit While
Else
MessageBox.Show("hola")
End If
Thread.Sleep(1000)
End While
End Sub
Private Sub bgw1_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgw1.RunWorkerCompleted
If e.Cancelled = True Then
MessageBox.Show("Cancelado!")
ElseIf e.Error IsNot Nothing Then
MessageBox.Show(e.Error.Message)
Else
MessageBox.Show("Fin!")
End If
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Control.CheckForIllegalCrossThreadCalls = False
End Sub
No hay comentarios.:
Publicar un comentario