Vinay Dwivedi
Vinay Dwivedi

Reputation: 767

Lock on Dispatcher

lock
{
  Dispatcher.BeginInvoke(DispatcherPriority.Send, (SendOrPostCallback)delegate(object o)
 {
   DoSomething();
 }
}

Does lock remains acquired Until Dispatcher completes its execution or released soon after sending the DoSomething(); for execution to Dispatcher?

Upvotes: 2

Views: 1089

Answers (1)

alex.b
alex.b

Reputation: 4567

  • Lock remains acquired until code under lock {} section completes its execution.
  • In your case that means: until Dispatcher.BeginInvoke completes its execution.
  • And as Dispatcher.BeginInvoke executes asynchronously, that means that lock gets released almost "immediately" - DoSomething() might start in the moment when lock has been already released.

Upvotes: 2

Related Questions