This example updates a progress bar: using System; using System. Threading; using System.Threading. Tasks; using System.Windows.
Forms; class SimpleProgressBar : Form { STAThread static void Main(string args) { Application. EnableVisualStyles(); Application. Run(new SimpleProgressBar()); } protected override void OnLoad(EventArgs e) { base.
OnLoad(e); int iterations = 100; ProgressBar pb = new ProgressBar(); pb. Maximum = iterations; pb. Dock = DockStyle.
Fill; Controls. Add(pb); Task. Create(delegate { Parallel.
For(0, iterations, I => { Thread. SpinWait(50000000); // do work here BeginInvoke((Action)delegate { pb. Value++; }); }); }); } } http://social.msdn.microsoft.com/Forums/en-US/parallelextensions/thread/38d7a436-e1d1-4af8-8525-791ebeed9663.
Where are you getting . Create in Task? I have the same namspaces imported and cannot find it.
– Nick Mar 2 at 4:33 @Nick: It looks like MSFT may have changed the Task class slightly between the Task Parallel CTP and the . NET 4.0 release. I suggest trying ContinueWith instead of Create.
– Robert Harvey? Mar 2 at 6:01.
There is no built-in support for this like what BackgroundWorker had. You can use SynchronizationContext directly; there's an excellent video here: rocksolidknowledge.com/ScreenCasts.mvc/W... The author develops two solutions in this video: one using SynchronizationContext and another using Task Continuations. For your problem, continuations will not work, but the SynchronizationContext approach would work fine.P.S.If you're creating reusable code, then when you capture SynchronizationContext.
Current, you should test for null and (if it is null) use a default-constructed SynchronizationContext instead. UPDATE: I've posted code for this on my blog. My solution is actually based on a Task that is scheduled back to the UI thread by a TaskScheduler which uses SynchronizationContext underneath.
Unlike the accepted answer, this solution will work for both WPF and Windows Forms.
The TPL isn't particularly oriented toward UI support, you can (still) use a BackgroundWorker for that. As for sending or processing intermediate results, there are new collectionclasses (ConcurrentQueue) to support that.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.