Backgroundworker problem

R

Robert Bevington

Hi everyone,

I'm trying to set up a backgroundworker so that I can dispaly a progress bar
in marquee mode while a long process (external API call) is running.

Public Sub bgw_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)

ImportDef.ProcessImport(MtTaskType.mtScript)

End Sub

My problem is getting the line that makes the API call ..ProcessImport to
work. I keep getting
the following error meesage when I call the API method:

Object reference not set to an instance of an object.

Has this got anything to do with the object being initially created outside
the background worker? If so, how do I pass this object to the
backgroundworker?

Thanks for any help

Robert
 
P

Patrice

Check ImportDef and MtTaskType.mtScript to see if they are valid (i.e. not
nothing). This error message means that an object variable is not
initialized (i.e. is "nothing").
 
R

Robert Bevington

Hi Patrice,

yes they are both nothing inside the Backgroundwork.DoWork method. Outside
of this Method they work fine. And that's exactly my problem. I defined the
objects as public, but that does not seem to help. That's why I thought it
had something to do with separate threads. I read something on delegates,
but couldn't really get my head round it. Could that be the solution?

Thanks for your help,

Rob
 
P

Patrice

My guess would be that you defined them both outside of the form (where they
work) and inside your form where you would use then those other unitializeed
variable.

Strip down your code to the minimal amount of code that shows the problem
and you'll likely find the cullprit. If not you'll have the shortest
possible amount of code to post so that others can give a look and hpefully
find the issue.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top