This is probably something simple I've missed.
Let's say I do (in loveley VB):
Dim t1 As New Task(Sub() Debug.WriteLine("t1"))
Dim t2 As Task = t1.ContinueWith(Sub() Debug.WriteLine("t2"))
Dim t3 As Task = t1.ContinueWith(Sub() Debug.WriteLine("t3"))
t1.Start()
Notice t1.ContinueWith is used twice. What is the preferred order of execution for these tasks? For me, it's either random or wrong.
The reason I want to do this...
TaskScheduler.FromCurrentSynchronizationContext()
(UI thread)This is made more complicated by the fact that step 4 is optional.
In the midst of all this, my tasks are bending backwards to set member properties so the UI and tasks can play nice. Perhaps I should ditch the Task result entirely and just stick to Synclocking my member variables. They are all only assigned once afterall.
Thanks, Tom
Concurrent tasks progress at the same time in the worker system but they don't progress simultaneously. Parallel tasks are executed by different workers at the same time. Concurrency refers to how a worker system handles multiple tasks while parallelism refers to how a worker system handles a single task.
ContinueWith(Action<Task,Object>, Object, TaskScheduler)Creates a continuation that receives caller-supplied state information and executes asynchronously when the target Task completes.
The Task Parallel Library (TPL) is based on the concept of a task, which represents an asynchronous operation. In some ways, a task resembles a thread or ThreadPool work item but at a higher level of abstraction. The term task parallelism refers to one or more independent tasks running concurrently.
The ContinueWith function is a method available on the task that allows executing code after the task has finished execution. In simple words it allows continuation. Things to note here is that ContinueWith also returns one Task. That means you can attach ContinueWith one task returned by this method.
The tasks are executed in a LIFO ordering for better memory locality. This can be changed of course if you use a differnt scheduler or if MS decides to "fix" the original one. I do not think that you should rely on this behaviour. Instead you could Unwrap your task to continue working on the previous task when it has completed. Otherwise you are waiting on the wrong thing. More infos can be found here: http://msdn.microsoft.com/en-us/library/ee795275.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With