I use Task Parallel Library and I need to synchronize access to a method but since Tasks don't necessarily create threads for asynchronous operations, I can't rely on using locks.
void Foo()
{
lock(SyncRoot)
{
// Do stuff...
}
}
What can I use instead of lock if I want to prevent simultaneous calls from multiple tasks to Foo? I need my tasks to call Foo, one by one.
- ContinueWith is not an option.
- I use .NET 4.