task-parallel-library

How to chain independent C# tasks?

爷,独闯天下 提交于 2021-02-07 13:31:40
问题 Let's say I have two independent async functions (that I don't control) that create Task objects: Task A(); Task B(); and some other non-async function void X(); How do I construct a single Task chain that executes all of these in sequence and allows further continuations (that will execute after X) to be appended? If I do this: Task Sequential() { return A() .ContinueWith(t => { B(); }) .ContinueWith(t => { X(); }); } that does not work, because B will start a new Task chain. If B takes a

How to chain independent C# tasks?

本秂侑毒 提交于 2021-02-07 13:31:09
问题 Let's say I have two independent async functions (that I don't control) that create Task objects: Task A(); Task B(); and some other non-async function void X(); How do I construct a single Task chain that executes all of these in sequence and allows further continuations (that will execute after X) to be appended? If I do this: Task Sequential() { return A() .ContinueWith(t => { B(); }) .ContinueWith(t => { X(); }); } that does not work, because B will start a new Task chain. If B takes a

How to chain independent C# tasks?

ぐ巨炮叔叔 提交于 2021-02-07 13:30:36
问题 Let's say I have two independent async functions (that I don't control) that create Task objects: Task A(); Task B(); and some other non-async function void X(); How do I construct a single Task chain that executes all of these in sequence and allows further continuations (that will execute after X) to be appended? If I do this: Task Sequential() { return A() .ContinueWith(t => { B(); }) .ContinueWith(t => { X(); }); } that does not work, because B will start a new Task chain. If B takes a

How to chain independent C# tasks?

青春壹個敷衍的年華 提交于 2021-02-07 13:29:10
问题 Let's say I have two independent async functions (that I don't control) that create Task objects: Task A(); Task B(); and some other non-async function void X(); How do I construct a single Task chain that executes all of these in sequence and allows further continuations (that will execute after X) to be appended? If I do this: Task Sequential() { return A() .ContinueWith(t => { B(); }) .ContinueWith(t => { X(); }); } that does not work, because B will start a new Task chain. If B takes a

Alternative for Task.Wait in UI thread

心不动则不痛 提交于 2021-02-07 12:58:26
问题 I know it is bad to call Task.Wait in UI thread. It causes a deadlock. Please refer to Constructor invoke async method Await, and UI, and deadlocks! Oh my! Take the following code: public MainPage() { this.InitializeComponent(); step0(); step1(); } private async Task step0() { await Task.Delay(5000); System.Diagnostics.Debug.WriteLine("step 0"); } private async Task step1() { await Task.Delay(3000); System.Diagnostics.Debug.WriteLine("step 1"); } } How can I ensure that "step 0" is always

Multiple Short-lived TPL Dataflows versus Single Long-Running Flow

℡╲_俬逩灬. 提交于 2021-02-07 07:25:53
问题 I'm using TPL dataflow to process items off a queue in an Azure worker role. Should I have a single long running dataflow, or spawn a new flow for every messages I receive? If an error is thrown in a block, that block will stop accepting new messages. That means if there is an exception in a block, the whole dataflow will stop processing. I need to be able to withstand exception from something like invalid queue inputs without locking my dataflow. I see one of two options: I have a start a

How can I specify an unordered Execution Block using the TPL Dataflow Library?

北慕城南 提交于 2021-02-07 06:47:07
问题 I want to set up a TransformBlock that processes its item in parallel. Thus, I'm setting ExecutionDataflowBlockOptions.MaxDegreeOfParallelism to > 1. I don't care about the order of the messages but the documentation says: When you specify a maximum degree of parallelism that is larger than 1, multiple messages are processed simultaneously, and therefore, messages might not be processed in the order in which they are received. The order in which the messages are output from the block will,

Thread.Sleep vs. Task.Delay when using timeBeginPeriod / Task scheduling

二次信任 提交于 2021-02-06 21:42:58
问题 The bounty expires tomorrow . Answers to this question are eligible for a +50 reputation bounty. Thomas Weller wants to draw more attention to this question. Given the attached LINQ-Pad snippet. It creates 8 tasks, executes for 500ms and draws a graph on when the threads were actually running. On a 4 core CPU it may look like this: Now, if I add a Thread.Sleep or a Task.Delay within the thread loops, I can visualize the clock of the windows system timer (~15ms): Now, there's also the

Thread.Sleep vs. Task.Delay when using timeBeginPeriod / Task scheduling

别说谁变了你拦得住时间么 提交于 2021-02-06 21:38:59
问题 The bounty expires tomorrow . Answers to this question are eligible for a +50 reputation bounty. Thomas Weller wants to draw more attention to this question. Given the attached LINQ-Pad snippet. It creates 8 tasks, executes for 500ms and draws a graph on when the threads were actually running. On a 4 core CPU it may look like this: Now, if I add a Thread.Sleep or a Task.Delay within the thread loops, I can visualize the clock of the windows system timer (~15ms): Now, there's also the

Ignore async without await compilation warning

爱⌒轻易说出口 提交于 2021-02-06 12:46:27
问题 I have a base controller with the following abstract method: [HttpDelete] public abstract Task<IHttpActionResult> Delete(int id); In one particular controller, I don't want to implement deletion, so the method looks like this: public override async Task<IHttpActionResult> Delete(int id) { return ResponseMessage(Request.CreateResponse(HttpStatusCode.MethodNotAllowed, new NotSupportedException())); } Although the above code compiles, I get a warning: This async method lacks 'await' operators