Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 2.11 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Creating Dialog with WebBrowser from BackgroundWorker
  2. protected bool ValidatePage( bool pagePasses, string msg ) {
  3.   if ( pagePasses == false ) {
  4.     AbortIgnoreSuspend ais = new AbortIgnoreSuspend( responsehtml, msg );
  5.     ais.ShowDialog();
  6.     switch ( ais.DialogResult ) {
  7.       case DialogResult.Abort: // Aborts entire thread
  8.         Abort = true;
  9.         worker.CancelAsync();
  10.         return false;
  11.       case DialogResult.Cancel: // Aborts this case
  12.         Abort = true;
  13.         return false;
  14.       case DialogResult.Ignore: // Ignore and continue
  15.         return true;
  16.       case DialogResult.Retry:  // Debug
  17.         Debug.Assert( false, "Suspending Thread" );
  18.         return true; // Will return you to calling thread and allow you to continue
  19.       default:
  20.         return true;
  21.     }
  22.   }
  23.   return true;
  24. }
  25.        
  26. protected bool ValidatePage( bool pagePasses, string msg ) {
  27.   if ( pagePasses == false ) {
  28.     bool setAbort = false;
  29.     bool assertError = false;
  30.     bool cancelWorker = false;
  31.     bool returnContinue = true;
  32.  
  33.     Thread th = new Thread( () => {
  34.       AbortIgnoreSuspend ais = new AbortIgnoreSuspend( responsehtml, msg );
  35.       ais.ShowDialog();
  36.       switch ( ais.DialogResult ) {
  37.         case DialogResult.Abort: // Aborts entire thread
  38.           setAbort = true;
  39.           cancelWorker = true;
  40.           returnContinue = false;
  41.           break;
  42.         case DialogResult.Cancel: // Aborts this case
  43.           setAbort = true;
  44.           returnContinue = false;
  45.           break;
  46.         case DialogResult.Ignore: // Ignore and continue
  47.           returnContinue = true;
  48.           break;
  49.         case DialogResult.Retry:  // Debug
  50.           assertError = true;
  51.           returnContinue = true; // Will return you to calling thread and allow you to continue
  52.           break;
  53.         default:
  54.           returnContinue = true;
  55.           break;
  56.       }
  57.  
  58.     } );
  59.     th.SetApartmentState( ApartmentState.STA );
  60.     th.Start();
  61.     th.Join();
  62.  
  63.     Abort = setAbort;
  64.     Debug.Assert( !assertError, "Suspending thread for debugging" );
  65.     if ( cancelWorker ) { worker.CancelAsync(); }
  66.     return returnContinue;
  67.   }
  68.   return true;
  69. }