how to retry a backgroundworker


hi,

i have application uses backgroundworker downloads lot of data database, in order keep main form responsive. bgw can raise timeout exception: in case want stop bgw , want retry bgw until execution performed , finished without exception raised. in meanwhile - - main window must responsive, can't use cycle in main thread. can me?
thank you

bgw.runworkercompleted += (s, e) =>                                       {                                          if (e.error != null)                                          {                                             console.writeline(e.error);                                             bgw.runworkerasync();                                          }                                       };

if not handle exception in dowork event, bgw assign exception error property.

in runworkercompleted event, can check e.error property.

if exception occurs, reset backgroud worker , run again.

one more thing should uncheck enable code in debugging options




Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments