c# - WaitAll for multiple handles on a STA thread is not supported -
- why error message? "waitall multiple handles on sta thread not supported."
- should use [mtathreadattribute] attribut? update: dosn't work wpf applications!
note: error @ line waithandle.waitall(doneevents); i'm using standard wpf project.
private void search() { const int cpus = 2; var doneevents = new manualresetevent[cpus]; // configure , launch threads using threadpool: (int = 0; < cpus; i++) { doneevents[i] = new manualresetevent(false); var f = new indexer(paths[i], doneevents[i]); threadpool.queueuserworkitem(f.waitcallback, i); } // wait threads in pool waithandle.waitall(doneevents); debug.writeline("search completed!"); }
update: following solution doesn’t work wpf applications! not possible change main application attribute mtathreadattribute. result in following error:
error: "waitall multiple handles on sta thread not supported."
what using tasks threading you.
http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.aspx
var task1 = task.factory.startnew(() => dosomework()); var task2 = task.factory.startnew(() => dosomework()); var task3 = task.factory.startnew(() => dosomework()); task.waitall(task1, task2, task3);
Comments
Post a Comment