
Untitled
By: a guest on
Apr 26th, 2012 | syntax:
None | size: 1.48 KB | hits: 18 | expires: Never
how do i start many threads in a queue?
private void Paste()
{
foreach (ListViewItem item in copiedItems)
{
Thread pasteC = new Thread(unused => fmc.PasteFromCopy(item.Text, somePath));
pasteC.Start();
}
}
public void PasteFromCopy(string source,string dest)
{
if (IsFolder(source))
{
CopyDirectory(source, dest);
}
else
{
CopyStream(source, dest);
}
}
private void Paste()
{
foreach (ListViewItem item in copiedItems)
{
fmc.PasteFromCopy(item.Text, somePath);
}
}
private void Paste()
{
var thread = new Thread(() =>
{
foreach (ListViewItem item in copiedItems)
{
fmc.PasteFromCopy(item.Text, somePath);
}
});
thread.Start();
}
public void PasteFromCopy(string source,string dest)
{
lock(this)
{
if (IsFolder(source))
{
CopyDirectory(source, dest);
}
else
{
CopyStream(source, dest);
}
}
}
object _sync;
ManualResetEvent _start;
Queue<KeyValuePair<string, string>> _copyQueue;
private void Paste()
{
foreach (ListViewItem item in copiedItems)
_copyQueue.Enqueue(new KeyValuePair<string, string>(item.text, somepath));
}
void Thread()
{
start.Wait();
while(_copyQueue.Count > 0)
{
lock(_sync)
{
if(_copyQueue.Count == 0)
break;
new Task(PasteFromCopy(_copyQueue.Dequeue()));
}
}
}