c# - Call a method that has already been called in a new thread -


i have method "importexcel" called in new thread:

[stathread]     private void btnimportexcel_click(object sender, eventargs e)     {         // start setting new thread using delegate threadstart         // tell entry function (the function call first in thread)         // think of main() new thread.         threadstart theprogress = new threadstart(importexcel);          // thread create using delegate         thread startprogress = new thread(theprogress);         startprogress.setapartmentstate(apartmentstate.sta);          // can give name (optional)         startprogress.name = "book detail scrapper";          // start execution         startprogress.start();                 } 

now within importexcel() function, there try catch block. in catch block, if particular exception occurs, wish call importexcel() function again. how do that?

probably add 1 more level of indirection handle such issue:

private void trymultimpleimportexcel() {     boolean cantryagain = true;      while( cantryagain)     {         try         {             importexcel();             cantryagain = false;         }         catch(notcriticaltryagainexception exc)         {             logger.log(exc);         }         catch(exception critexc)         {             cantryagain = false;         }     } }       // ...     threadstart theprogress = new threadstart(trymultimpleimportexcel);     // ..     startprogress.start();     

also:

if want allow user stop possibly endless processing, may want use cancellationtoken, described here - how use cancellationtoken property?. @mikeofsst.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -