c# - Can events only have one call out at a time? -


say have event this:

someclass.someevent += mymethodtocall();  ...  public void mymethodtocall() {      if (checktoseeifformisalreadyshowing())      {          someform someform = new someform();          someform.showdialog();      }      else      {          dosomestuff();      } } 

if user interaction someform causes someevent fire again mymethodtocall called again while someform still showing?

my evidence seems show not.

my question why? event happened again. why wouldn't mymethodtocall called again (and end calling dosomestuff()?

i guessing not possible (still not sure why). assuming not possible, can show dialog on separate thread (begininvoke)? (i seem recall ui needs happen on same thread hesitant try that).

i need have event called again if happens again (even if someform dialog still showing. ideas on how can great!

note: contrived example, have tried condense complex code example demonstrates real issue working with. (meaning please don't attack example.)

based on comments above, here's think happens.

the someclass.someevent event fired background thread belongs driver. background thread designed wait on internal handle or queue, , trigger event when needed.

what did, call showdialog on background thread. blocks thread, not able continue triggering event until handler returns, happen after dialog closed.

the solution suggest avoid showing ui on driver's background thread, , keep event handler short possible. need call begininvoke on control, in order call showdialog ui thread.

so code this:

someclass.someevent += someeventhandler; ... ... ... void someeventhandler() {     // i'm assuming code in class derived form     this.begininvoke(new methodinvoker(handleeventonuithread)); }  void handlereventonuithread() {     if (checktoseeifformisalreadyshowing())     {         someform someform = new someform();         someform.showdialog();     }     else     {         dosomestuff();     } } 

this way, handling of someclass.someevent return immediately, , background thread able trigger event again when needed.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -