Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Background worker cancelling from another form

Posted on 2016-09-23
8
Medium Priority
?
38 Views
Last Modified: 2016-10-09
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.

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

Open in new window

0
Comment
Question by:K-9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
8 Comments
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 41812492
You never assign a value to your variable myParent in the code you show.  Once you set that to the 'parent' form you should be able to do what you want (BackgroundWorker1 would need to be a public variable).
0
 

Author Comment

by:K-9
ID: 41812493
Yes I did: Private myParent As frmGMapNet
frmGMapNew is the form where the Backgroundworker is.
0
 

Author Comment

by:K-9
ID: 41812502
Wow.. that's weird.  If I use frmGMapNew.BackgroundWorker1.CancelAsync() it works.  For some reason it doesn't like using myParent
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 45

Expert Comment

by:AndyAinscow
ID: 41812534
Sounds like you have the BackgroundWorker1 as a static variable in that case.
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 41812537
ps.  I told you why the myParent doesn't work in my first comment.
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 41828034
My first comment points out what is wrong with the code supplied and how to fix it.
#a41812492
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question