K-9
asked on
Background worker cancelling from another form
Using vb.net for an application i'm developing. During a backgroundworker routine, I have a semi-transparent overlay form over top with a progress bar and cancel button. However when I try to cancel I get the error: Object reference not set to an instance of an object.
How can I cancel a backgroundworker from another form? This is my code from the second (overlay) form.
How can I cancel a backgroundworker from another form? This is my code from the second (overlay) form.
Public Class CISMapOverlay
Private myParent As frmGMapNet
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadLabel2.Click
Me.myParent.BackgroundWorker1.CancelAsync()
Me.Hide()
End Sub
Public Sub New()
' This call is required by the designer.
InitializeComponent()
Me.myParent = myParent
' Add any initialization after the InitializeComponent() call.
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Wow.. that's weird. If I use frmGMapNew.BackgroundWorke r1.CancelA sync() it works. For some reason it doesn't like using myParent
Sounds like you have the BackgroundWorker1 as a static variable in that case.
ps. I told you why the myParent doesn't work in my first comment.
My first comment points out what is wrong with the code supplied and how to fix it.
#a41812492
#a41812492
ASKER
frmGMapNew is the form where the Backgroundworker is.