Ok , i susspect it has to do with cross threading, trying to update the form thread from the background worker thread....
mmmm...
ok lets try it like so
Code:Public Class Form1 Private WithEvents Bgw As New ComponentModel.BackgroundWorker Private WithEvents St As New Diagnostics.Stopwatch Private Event Tick(Ms As Integer) Private CancelBgw As Boolean = False Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load With Bgw .WorkerReportsProgress = True '<----Added .WorkerSupportsCancellation = True If Not .IsBusy Then CancelBgw = False .RunWorkerAsync() End If End With End Sub Private Sub Form1_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing Me.CancelBgw = True End Sub Private Sub Bgw_DoWork(sender As Object, e As DoWorkEventArgs) Handles Bgw.DoWork St.Start() While Not Me.CancelBgw If St.ElapsedMilliseconds >= 50 Then Bgw.ReportProgress(1) '<----Added (Its a bit of an hack) 'RaiseEvent Tick(St.ElapsedMilliseconds) '<----Removed St.Reset() St.Start() End If End While End Sub 'Private Sub Form1_Tick(Ms As Integer) Handles Me.Tick ' Debug.Print(Ms.ToString) 'End Sub Private Sub Bgw_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles Bgw.ProgressChanged 'Result beeing that the drawchart sub is called from the ui thread. drawchart End Sub End Class




Reply With Quote
