Skip to main content

Microsoft Silverlight

Answered Question Asychronous Thread RSS Feed

(0)

nz
nz

Member

Member

9 points

14 Posts

Asychronous Thread

Guys, Need help with using Asychronous Thread in silverlight ? I try to use a ParameterizedThreadStart, because I got a parameterized method. Can anyone kindly tell me how to use it?

 

many thx

bryant
bryant

Star

Star

9937 points

1,629 Posts

Silverlight MVP
Answered Question

Re: Asychronous Thread

You'd be better off using the BackgroundWorker since you can pass in parameters to it.

-- bryant

Blog | Twitter
_________________
Dont forget to click "Mark as Answer" on the post that helped you.

nz
nz

Member

Member

9 points

14 Posts

Re: Asychronous Thread

Could u simply explain how BackgroundWorker pass parameters? I think it DoWork() take a event handler.

bryant
bryant

Star

Star

9937 points

1,629 Posts

Silverlight MVP
Answered Question

Re: Re: Asychronous Thread

You call worker.RunWorkerAsync(object parameter) and in the do work event handler you can grab the object from the Argument property on DoWorkEventArgs.

-- bryant

Blog | Twitter
_________________
Dont forget to click "Mark as Answer" on the post that helped you.

nz
nz

Member

Member

9 points

14 Posts

Re: Re: Asychronous Thread

It seems only working for one parameter, how about two?

nz
nz

Member

Member

9 points

14 Posts

Re: Re: Asychronous Thread

I got a error with message in DoWork(), could u please explain why this will happen 

Invalid cross-thread access.

 

many thx

bryant
bryant

Star

Star

9937 points

1,629 Posts

Silverlight MVP

Re: Re: Re: Asychronous Thread

You can't set things in your UI from code in the background thread (or any thread except the UI thread).

What are you trying to accomplish in DoWork?

-- bryant

Blog | Twitter
_________________
Dont forget to click "Mark as Answer" on the post that helped you.

bryant
bryant

Star

Star

9937 points

1,629 Posts

Silverlight MVP
Answered Question

Re: Re: Re: Asychronous Thread

For two parameters just create your own class that has the two parameters or use a KeyValuePair.

-- bryant

Blog | Twitter
_________________
Dont forget to click "Mark as Answer" on the post that helped you.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities