task-parallel-library

Default SynchronizationContext vs Default TaskScheduler

拈花ヽ惹草 提交于 2020-01-11 15:27:31
问题 This is going to be a bit long, so please bear with me. I was thinking that the behavior of the default task scheduler ( ThreadPoolTaskScheduler ) is very similar to that of the default " ThreadPool " SynchronizationContext (the latter can be referenced implicitly via await or explicitly via TaskScheduler.FromCurrentSynchronizationContext() ). They both schedule tasks to be executed on a random ThreadPool thread. In fact, SynchronizationContext.Post merely calls ThreadPool.QueueUserWorkItem .

What is the difference between Task<> and IAsyncOperation<>

天大地大妈咪最大 提交于 2020-01-11 04:24:21
问题 I am writing a metro app. This works: HttpClient client = new HttpClient(); var bytes = await client.GetByteArrayAsync(new Uri("www.microsoft.com")); This doesn't: var folder = Windows.Storage.ApplicationData.Current.LocalFolder; var file = await folder.GetFileAsync("text.txt"); The first one returns a Task<>, the second one return an IAsyncOperation<> What is the difference? Why are there two different types? How can I fix the second sample? 回答1: IAsyncOperation is a metro asynchronous

How to disable Task Parallel Library's ETW EventSource in a Universal App?

﹥>﹥吖頭↗ 提交于 2020-01-11 03:22:27
问题 Task Parallel Library uses Event Tracing for Windows (ETW) for logging. Apparently, there is a bug related to logging, in either TPL or ETW, surfacing under Windows Phone or Windows Store .NET Runtime. The original issue is described here. A possible workaround would be to disable the TPL's ETW EventSource . How do I disable it from within a Universal Windows app , if I really want to? Reflection works for a Desktop app, but not for a WP/WinRT app. EventCommand.Disable is not recognized as a

Task not in a faulted state when an exception is thrown

妖精的绣舞 提交于 2020-01-10 04:47:06
问题 I can't seem to figure out why my task is not in a faulted state when an exception is thrown in the following sample (assume engine.Send(...) throws an exception): var receiverTask = new Task<Task>(async () => { result = await Task.FromResult(engine.Send(someObject)); }); receiverTask.Start(); receiverTask.Wait(); if I do receiverTask.IsFaulted after the receiverTask.Wait() it returns false instead of true as I would expect. I have been reading that I need to use something like the following

Reading Material on Async Programming Practices [closed]

别来无恙 提交于 2020-01-09 19:40:59
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Asynchronous programming is the next up-and-coming paradigm... or so it seems. I have been programming in Node.js for the past few months and have been learning to write code this way. I have a coworker who works in Silverlight and I have been trying to teach him how to use the TPL. I have also been showing him

Reading Material on Async Programming Practices [closed]

怎甘沉沦 提交于 2020-01-09 19:40:29
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Asynchronous programming is the next up-and-coming paradigm... or so it seems. I have been programming in Node.js for the past few months and have been learning to write code this way. I have a coworker who works in Silverlight and I have been trying to teach him how to use the TPL. I have also been showing him

Reading Material on Async Programming Practices [closed]

可紊 提交于 2020-01-09 19:40:05
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Asynchronous programming is the next up-and-coming paradigm... or so it seems. I have been programming in Node.js for the past few months and have been learning to write code this way. I have a coworker who works in Silverlight and I have been trying to teach him how to use the TPL. I have also been showing him

Why doesn't my process terminate when Task has unhandled exception?

那年仲夏 提交于 2020-01-09 19:09:27
问题 I am building a Windows Service with .NET 4.0. I have various unhandled exceptions thrown in Tasks, but they do not terminate my process as the MSDN documentation states (Parallel Tasks - see Unobserved Task Exceptions). "If you don't give a faulted task the opportunity to propagate its exceptions (for example, by calling the Wait method), the runtime will escalate the task's unobserved exceptions according to the current .NET exception policy when the task is garbage-collected." It behaves

Why doesn't my process terminate when Task has unhandled exception?

无人久伴 提交于 2020-01-09 19:04:46
问题 I am building a Windows Service with .NET 4.0. I have various unhandled exceptions thrown in Tasks, but they do not terminate my process as the MSDN documentation states (Parallel Tasks - see Unobserved Task Exceptions). "If you don't give a faulted task the opportunity to propagate its exceptions (for example, by calling the Wait method), the runtime will escalate the task's unobserved exceptions according to the current .NET exception policy when the task is garbage-collected." It behaves

Workaround for issue in .NET 4.0 where SynchronizationContext.Current is null

烈酒焚心 提交于 2020-01-09 10:33:08
问题 What is a workaround for the issue where the SynchronizationContext.Current is null unexpectedly on the main thread in .NET 4.0? See: SynchronizationContext.Current is null in Continuation on the main UI thread 回答1: I created several extension methods that matched ContinueWith and StartNew except that they also take an additional SyncronizationContext . I then use this argument to restore the expected SynchronizationContext before executing the action: Below, I've given examples: public