task-parallel-library

Finding out where unobservedTaskException is thrown: stacktrace is null

你。 提交于 2021-01-01 07:59:04
问题 I have a large C# appication using third party libraries and somewhere in the application a task is run which is not awaited and throws an exception. So I added an event handler to TaskScheduler.UnobservedTaskException: TaskScheduler.UnobservedTaskException += (sender, args) => { _logger.Error(args.Exception); args.SetObserved(); }; However, when this handler is executed, I get some exception with a stacktrace of null: System.AggregateException: A Task's exception(s) were not observed either

C#. What happens if “after await” thread is busy?

耗尽温柔 提交于 2020-12-31 10:54:55
问题 What happens in C# when awaitable task is finished but the thread in which async method had been started is unavailable (handles another request for example) ? Will then be used another thread instead of the first one, or execution will wait until the busy thread is available ? Thanks in advance for your answers. 回答1: That depends on the SynchronizationContext of the thread on which the continuation was scheduled. For example, when you're using async/await in an app with a UI thread, like an

C#. What happens if “after await” thread is busy?

Deadly 提交于 2020-12-31 10:54:54
问题 What happens in C# when awaitable task is finished but the thread in which async method had been started is unavailable (handles another request for example) ? Will then be used another thread instead of the first one, or execution will wait until the busy thread is available ? Thanks in advance for your answers. 回答1: That depends on the SynchronizationContext of the thread on which the continuation was scheduled. For example, when you're using async/await in an app with a UI thread, like an

C#. What happens if “after await” thread is busy?

隐身守侯 提交于 2020-12-31 10:54:31
问题 What happens in C# when awaitable task is finished but the thread in which async method had been started is unavailable (handles another request for example) ? Will then be used another thread instead of the first one, or execution will wait until the busy thread is available ? Thanks in advance for your answers. 回答1: That depends on the SynchronizationContext of the thread on which the continuation was scheduled. For example, when you're using async/await in an app with a UI thread, like an

C#. What happens if “after await” thread is busy?

余生长醉 提交于 2020-12-31 10:54:27
问题 What happens in C# when awaitable task is finished but the thread in which async method had been started is unavailable (handles another request for example) ? Will then be used another thread instead of the first one, or execution will wait until the busy thread is available ? Thanks in advance for your answers. 回答1: That depends on the SynchronizationContext of the thread on which the continuation was scheduled. For example, when you're using async/await in an app with a UI thread, like an

C#. What happens if “after await” thread is busy?

ぐ巨炮叔叔 提交于 2020-12-31 10:54:12
问题 What happens in C# when awaitable task is finished but the thread in which async method had been started is unavailable (handles another request for example) ? Will then be used another thread instead of the first one, or execution will wait until the busy thread is available ? Thanks in advance for your answers. 回答1: That depends on the SynchronizationContext of the thread on which the continuation was scheduled. For example, when you're using async/await in an app with a UI thread, like an

await Task.Delay(foo); takes seconds instead of ms

╄→гoц情女王★ 提交于 2020-12-29 04:20:25
问题 Using a variable delay in Task.Delay randomly takes seconds instead of milliseconds when combined with a IO-like operation. Code to reproduce: using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApplication { class Program { static void Main(string[] args) { Task[] wait = { new delayTest().looper(5250, 20), new delayTest().looper(3500, 30), new delayTest().looper

await Task.Delay(foo); takes seconds instead of ms

谁都会走 提交于 2020-12-29 04:19:48
问题 Using a variable delay in Task.Delay randomly takes seconds instead of milliseconds when combined with a IO-like operation. Code to reproduce: using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApplication { class Program { static void Main(string[] args) { Task[] wait = { new delayTest().looper(5250, 20), new delayTest().looper(3500, 30), new delayTest().looper

await Task.Delay(foo); takes seconds instead of ms

99封情书 提交于 2020-12-29 04:19:22
问题 Using a variable delay in Task.Delay randomly takes seconds instead of milliseconds when combined with a IO-like operation. Code to reproduce: using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApplication { class Program { static void Main(string[] args) { Task[] wait = { new delayTest().looper(5250, 20), new delayTest().looper(3500, 30), new delayTest().looper

TaskCompletionSource : When to use SetResult() versus TrySetResult(), etc

假装没事ソ 提交于 2020-12-29 01:47:43
问题 I'm trying to wrap my head around the TPL, the new async / await features in C# 5, and the mysteries of TaskCompletionSource . One thing that isn't clear to me is when to use SetResult , SetException , and SetCancel versus TrySetResult , TrySetException and TrySetCancel . This is what MSDN has to say: This operation will return false if the Task is already in one of the three final states: RanToCompletion, Faulted, or Canceled. This method also returns false if the underlying Task has already