c# - WaitAll for multiple handles on a STA thread is not supported -


  1. why error message? "waitall multiple handles on sta thread not supported."
  2. 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

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -