Benny
Benny

Reputation: 8815

how does BackgroundWorker work under the hood?

how does it knows when to/not to marshal call to the UI thread in it's progresschanged event handler?

I know SynchronizationContext.Current can do the trick, but this property is only set in the main UI thread, what if the backgroundworker is created on another background thread?

Can anybody kindly explain?

Upvotes: 2

Views: 459

Answers (1)

Matthias
Matthias

Reputation: 12259

According to the Reflector, BackgroundWorker.RunWorkAsync which is called from the UI-thread uses AsyncOperationManager.CreateOperation.

This method accesses SynchronizationContext.Current (or creates a new if none exists).

So the SynchronizationContext is saved when starting the BGW.

Upvotes: 4

Related Questions