Backgroundworker problem

  • Thread starter Thread starter Robert Bevington
  • Start date Start date
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
 
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").
 
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
 
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.
 
Back
Top