views:

94

answers:

1

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?

+3  A: 

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.

winSharp93
creates a new if none exists, this is the key point. thanks.
Benny