Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 1.48 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. how do i start many threads in a queue?
  2. private void Paste()
  3. {
  4.     foreach (ListViewItem item in copiedItems)
  5.     {
  6.         Thread pasteC = new Thread(unused => fmc.PasteFromCopy(item.Text, somePath));
  7.         pasteC.Start();
  8.     }
  9. }
  10.        
  11. public void PasteFromCopy(string source,string dest)
  12. {
  13.     if (IsFolder(source))
  14.     {
  15.         CopyDirectory(source, dest);
  16.     }
  17.     else
  18.     {
  19.         CopyStream(source, dest);
  20.     }
  21. }
  22.        
  23. private void Paste()
  24. {
  25.     foreach (ListViewItem item in copiedItems)
  26.     {
  27.         fmc.PasteFromCopy(item.Text, somePath);
  28.     }
  29. }
  30.        
  31. private void Paste()
  32. {
  33.     var thread = new Thread(() =>
  34.     {
  35.         foreach (ListViewItem item in copiedItems)
  36.         {
  37.             fmc.PasteFromCopy(item.Text, somePath);
  38.         }
  39.     });
  40.     thread.Start();
  41. }
  42.        
  43. public void PasteFromCopy(string source,string dest)
  44. {
  45.     lock(this)
  46.     {
  47.         if (IsFolder(source))
  48.         {
  49.             CopyDirectory(source, dest);
  50.         }
  51.         else
  52.         {
  53.             CopyStream(source, dest);
  54.  
  55.         }
  56.     }
  57. }
  58.        
  59. object _sync;
  60. ManualResetEvent _start;
  61. Queue<KeyValuePair<string, string>> _copyQueue;
  62.  
  63. private void Paste()
  64. {
  65.     foreach (ListViewItem item in copiedItems)
  66.         _copyQueue.Enqueue(new KeyValuePair<string, string>(item.text, somepath));
  67. }
  68.        
  69. void Thread()
  70. {
  71.    start.Wait();
  72.    while(_copyQueue.Count > 0)
  73.    {
  74.       lock(_sync)
  75.       {
  76.           if(_copyQueue.Count == 0)
  77.              break;
  78.            new Task(PasteFromCopy(_copyQueue.Dequeue()));
  79.       }
  80.    }
  81. }