Reputation: 1151
I have a non iterative code inside a BackGroundWorker, so I can´t check if CancellationPendig.
The code is the following.
Private Sub BgW1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BgW1.DoWork
Try
Dim conn As New MySqlConnection(My.Settings.MySQL_Cnn_Cfg)
Dim Adp As New MySqlDataAdapter
Dim TablaDatos As New DataTable
conn.Open()
Using cmd As New MySqlCommand()
cmd.CommandType = CommandType.Text
cmd.Connection = conn
cmd.CommandText = e.Argument
Adp.SelectCommand = cmd
TablaDatos.Clear()
Adp.Fill(TablaDatos)
e.Result = TablaDatos
End Using
Catch ex As Exception
e.Result = "Error!"
e.Cancel = True
End Try
End Sub
The BackGroundWorker receives a query string and return a DataTable and it works if the remote server make a fast answer, but with complex querys that take some time I cant' cancel the process, or at least I don't know how.
I already try
BgW1.Dispose()
With no success, so There's another way to stop a BackGroundWorker?
Upvotes: 3
Views: 252
Reputation: 7242
No you cannot.
The only way I can see this working is if you have the ID
of the MySQL
connection, and another button that when you click it kills that process, in that sense the query would stop and the backgrounworker would finish.
Upvotes: 4