-
-
Notifications
You must be signed in to change notification settings - Fork 356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sometimes AsyncContext would not stop #242
Comments
Unfortunately, AsyncEx can't help you with that, since it doesn't have that information.
The If the screenshot you posted is at a time when you expected the |
By private void Enqueue(Task task, bool propagateExceptions)
{
OperationStarted();
task.ContinueWith(_ => OperationCompleted(), CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, _taskScheduler);
_queue.TryAdd(task, propagateExceptions);
tSynchronizationContext(WinFormsSynchronizationContext).
}
private void OperationCompleted()
{
var newCount = Interlocked.Decrement(ref _outstandingOperations);
if (newCount == 0)
_queue.CompleteAdding();
}
public void Execute()
{
SynchronizationContextSwitcher.ApplyContext(_synchronizationContext, () =>
{
var tasks = _queue.GetConsumingEnumerable();
foreach (var task in tasks)
{
_taskScheduler.DoTryExecuteTask(task.Item1);
// Propagate exception if necessary.
if (task.Item2)
task.Item1.WaitAndUnwrapException();
}
});
} This is where _outstandingOperations is mainly increased and decreased (the other 2 is in |
OK I found out that AsyncVoidMethodBuilder does call SynchronizationContext.OperationStarted. Anyway, I decide to forcefully decrease _outstandingOperations when I believe my program should exit, using reflection haha |
Ah, I forgot that it's also used in
I strongly recommend against this. I recommend finding what code isn't completing and ensure it completes, instead. |
I understand that AsyncContext would not stop until all tasks are finished. I want to find out which tasks are out running. But I didn't find out a good way. Both the Tasks view and Parallel Stacks view didn't help. Then I found something strange, the _outstandingOperations is not matching with _queue.Count
I read the source but didn't find any clue. Can you help me?
The text was updated successfully, but these errors were encountered: