यहाँ पूरा हो गया है जब हम Task.Factory.StartNew()
का उपयोग कर तो हम .ContinueWith()
ब्लॉक का उपयोग करते हैं प्रत्येक कार्य खत्म निर्धारित करने के लिए कर सकते हैं एक से अधिक कार्य शुरू से अधिक कार्यकैसे जब सभी कार्य
Task.Factory.StartNew(() =>
{
//foreach (KeyValuePair<string, string> entry in dicList)
Parallel.ForEach(dicList,
entry =>
{
//create and add the Progress in UI thread
var ucProgress = (Progress)fpPanel.Invoke(createProgress, entry);
//execute ucProgress.Process(); in non-UI thread in parallel.
//the .Process(); must update UI by using *Invoke
ucProgress.Process();
System.Threading.Thread.SpinWait(5000000);
});
});
.ContinueWith(task =>
{
//to handle exceptions use task.Exception member
var progressBar = (ProgressBar)task.AsyncState;
if (!task.IsCancelled)
{
//hide progress bar here and reset pb.Value = 0
}
},
TaskScheduler.FromCurrentSynchronizationContext() //update UI from UI thread
);
शुरू करने के लिए नमूना कोड है निर्धारित करने के लिए। मेरा मतलब है कि प्रत्येक कार्य पूरा करने के लिए एक बार ब्लॉक आग के साथ जारी रखें। तो मैं सिर्फ यह जानना चाहता हूं कि टीपीएल पुस्तकालय में कोई तंत्र है। अगर मैं Task.Factory.StartNew()
का उपयोग करके 10 कार्य शुरू करता हूं तो 10 कार्य समाप्त होने के बाद मैं कैसे सूचित करूं। कृपया नमूना कोड के साथ कुछ अंतर्दृष्टि दें।
क्या उन्हें एक के बाद एक चलाने की जरूरत है? – Mez