Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to chain tasks within each thread
    primarykey
    data
    text
    <p>I have a requirement for copying several hundred tables using bulkcopy. So far I got the following code.</p> <pre><code>// from UI main thread private void test1() { LimitedTaskScheduler scheduler = new LimitedTaskScheduler(4); TaskFactory factory = new TaskFactory(scheduler); foreach (DataRow row in tabList.Rows) // Loop over the rows. { string tabName = row[tabList.Columns["TableName"]].ToString(); factory.StartNew&lt;string&gt;( () =&gt; { Console.WriteLine("{0} on thread {1}", tabName, Thread.CurrentThread.ManagedThreadId); TableCopyer tc1 = new TableCopyer(); // pass progressbar and label into tc1 instance to update the progressbar and label tc1.Bar1 = bar1; tc1.L1 = l1; tc1.EntityCopy(AppInfo.SrcDBMSPath, AppInfo.DestDBMSPath, tabName, ""); return tabName; }); } } // inside TableCopier class private void OnSqlRowsCopied(object sender, SqlRowsCopiedEventArgs e) { try { int rowCopied = int.Parse(e.RowsCopied.ToString()); double result = (double.Parse(rowCopied.ToString()) / double.Parse(TotalRows.ToString())); int prsent = int.Parse(Math.Round((result * 100), 0).ToString()); SetProgressbar(prsent); } catch { throw; } } </code></pre> <p>LimitedTaskScheduler is coming from <a href="http://msdn.microsoft.com/en-us/library/ee789351.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ee789351.aspx</a></p> <p>My questions are</p> <ol> <li><p>How do I chain the tasks so that each will start only upon the finish of the prior task within each thread? I limited the max parallel thread to 4. I want to chain the tasks within the threads because the tasks being performed within a thread will reuse the same progressbar in a way one finishes and another starts. </p></li> <li><p>I have 4 progress bar painted on UI, bar1, bar2, bar3, bar4. How do I associate each progressbar with a particular thread so that the user can see 4 running progress at the same time?</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload