-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation
Description
Hello,
In the readme it says:
it's fine if the current SynchronizationContext is changed or ConfigureAwait(false) is used by an awaited method within the guarded section
But later it says:
So if you're executing third party methods within the guarded section and if you're concerned that they might change the current SynchronizationContext then just wrap them in Task.Run or something similar.
So if I understood correctly by "awaited method" you mean an async one? Not one that just returns a Task, right?
Basically, is there any difference in the below methods? Or they both should run fine even without Task.Run? When exactly you should wrap a method in Task.Run? Thanks
Task TaskMethod(){
SynchronizationContext.SetSynchronizationContext(null);
return Task.Delay(1).ConfigureAwait(false);
}
async Task AsyncTaskMethod(){
SynchronizationContext.SetSynchronizationContext(null);
await Task.Delay(1).ConfigureAwait(false);
}
var asyncLock = new ReentrantAsyncLock();
await using (await asyncLock.LockAsync(CancellationToken.None))
{
await TaskMethod();
}
await using (await asyncLock.LockAsync(CancellationToken.None))
{
await AsyncTaskMethod();
}Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation