c# - Parallel - threads? loops? -


so have application uses google earth. click button , new form pops up. form remains while user clicks places on google earth in main form. after form pops up, loop runs waits user click "ok" or "cancel". currently, cannot user interaction main google earth form while pop there.

i'm not sure best way approach it's hard search relevant.

here's i've tried far:

this first part of code after button pressed common below:

            form totarea = new aspe.gui.optimizationwizard.totalarea();             dialogresult dr1 = new dialogresult();             thread t = new thread(() => dr1 = totarea.showdialog());             t.start();             //totarea.topmost = true;             bool firstcall = true;             dynamic[] polystuff = null; 

simply running while loop after dialog pops (i knew fail):

        while (dr1 != dialogresult.ok & dr1 != dialogresult.cancel)         {             //do stuff         }  

using "parallel.for":

        parallel.for(0, 1, =>         {          //do stuff         }); 

this fails because don't know how make wait me click dialog boxes.

using "parallel while" http://blogs.msdn.com/b/pfxteam/archive/2009/08/12/9867246.aspx : paralleloptions paralleloptions = new paralleloptions();

        func<bool> condn = () => (dr1 != dialogresult.ok | dr1 != dialogresult.cancel);         action whilebody = () =>         {              //do stuff             }; 

and these functions:

        while(paralleloptions, condn, whilebody);       private static ienumerable<bool> iterateuntilfalse(func<bool> condition)     {         while (condition()) yield return true;     }     public static void while( paralleloptions paralleloptions, func<bool> condition, action body)     {         parallel.foreach(iterateuntilfalse(condition), paralleloptions,             ignored => body());     } 

and alien me, seems run so isn't in parallel @ all.

can suggest here?

thanks.

showdialog should halt execution until dialog result returned. because showing dialog in separate thread, it's not halting current one.

you can go using parallel.for , change code this:

if (dialogresult.ok == totarea.showdialog()) {      parallel.for(0, 1, =>      {           //do stuff      }); } 

you use task.factory if have in background:

var task = task.factory.startnew(() => { return totarea.showdialog(); }); task.wait(); if (task.result == dialogresult.ok) {      parallel.for(0, 1, =>      {           //do stuff      }); } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -