2012-01-21 15 views
12

Ho un problema con il mio programma Modulo WinApp che contiene una scheda Controllo con DLL controllo WebBrowser (GeckoFX).Arresto modulo WinApp senza errori o eccezioni .Net

La mia applicazione è in esecuzione senza eccezioni o altro. Potrebbe succedere dopo pochi minuti o dopo max 10 minuti. Nello studio visivo vedo l'applicazione terminare con il codice 0. Qualsiasi cosa.

Nel Program.cs prendo tutto questo excpetion non gestita

` // Add the event handler for handling UI thread exceptions to the event. 
       Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(UIThreadException); 

    // Set the unhandled exception mode to force all Windows Forms errors to go through 
    // our handler. 
        Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); 

// Add the event handler for handling non-UI thread exceptions to the event. 
       AppDomain.CurrentDomain.UnhandledException += 
        new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);` 

ho già Check in logger eventi Windows per qualsiasi errore, ma è pulito. Proprio come il Programma è terminato bene. Non so se è colpa di Gecko DLL ma non la penso così.

Uso httpWebRequest per scaricare un elenco che contiene alcuni URL.

Quindi utilizzo un Backgroundworker che legge l'elenco dell'URL e richiama il metodo Delegato AddTab Sospendi un po 'fino a quando la pagina non viene caricata e continua con altri richiami di AddTab.

Quando l'elenco è vuoto mi controllare se nella pagina DOM v'è una certa stringa Poi nel Backgroundworker Complete I chiudere tutte le schede e li smaltire e clicco su button1 cui avviare il Backgroundworker1.asyncall();

C'è qualcosa di sbagliato con la mia logica? Pubblicherò anche il codice, ho bisogno che sia troppo lungo ma ho davvero bisogno di capire dove potrebbe essere l'errore che termina la mia domanda. Se qualcuno può aiutarmi a capire perché si blocca senza alcun errore o altro, lo apprezzerò.

private void Start_Back_Click(object sender, EventArgs e) 
    {       
     List<Links> tempList = getListFromWeb(); 

     if (!backgroundWorker1.IsBusy) 
     { 
      backgroundWorker1.RunWorkerAsync(tempGoogle); 
     } 
    } 

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) 
     { 
      List<Links> temp = (List<Links>)e.Argument; 
      foreach (Links link in temp) 
      {     
       if (backgroundWorker1.CancellationPending) 
       { 
        e.Cancel = true; return;      
       } 
       _busy.WaitOne(); 

       if (tabs.InvokeRequired) 
       { 
         m_addTab addTabInvoke = addTabUrl; 
         Invoke(addTabInvoke, new Object[] { link.url, link.StringToSearch }); 
       } 
      } 
      Thread.Sleep(2000); 
      if (tabs.InvokeRequired) 
      { 
       foreach (Browser tempBrowser in ListCurrentBrowser) 
       { 
        if (backgroundWorker1.CancellationPending) 
        { 
         e.Cancel = true; 
         return; 
        } 
        _busy.WaitOne(); 
        Thread.Sleep(1000); 
        m_SeachTab addSearchInvoke = addTabPSearch; 
        Invoke(addSearchInvoke, tempBrowser); 
       } 
      } 
     } 

private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) 
     { //Check Stuff Error and Cancelled 
      if (e.Error != null) 
      {... } 
      else if (e.Cancelled) 
      { ....} 
      else //Else remove all tab 
      { 
       bool canRemove = this.TabCount >= 1; 
      if (canRemove) 
      { 
       WebBrowserTabPage tab = this.SelectedWebBrowserTagPage; 
       this.TabPages.Remove(tab); 
       tab.Dispose(); 
      } 
      **Start.Back.PerformClick();** //Click on button again to start another time the backgroundworker 
} 

}

+0

Molto improbabile che tu abbia effettivamente un errore o un'eccezione.Il codice è abbastanza infelice, in nessun modo Start.Back.PerformClick() potrebbe funzionare. E nessuno del codice BGW viene effettivamente eseguito sul thread di lavoro. Aggiungi un gestore di eventi per l'evento FormClosing del modulo e imposta un punto di interruzione su di esso. –

+0

Whay suggerisci di creare un codice migliore? Potrebbe dirmi come posso gestirlo? Creo il BackGroundworker e poi? Come posso riavviare il backgroundworker una volta terminato? Apprezzerò se puoi dirmi come potrei scrivere un codice migliore :) – user1107078

+1

possibile duplicato di [Arresti applicazioni con "Errore interno in .NET Runtime"] (http://stackoverflow.com/questions/4367664/application- si blocca-con-errore-interno-nella-rete-runtime) –

risposta

0

realtà quando si verifica un'eccezione non gestita in un altro thread l'intero processo viene terminato. È necessario eseguire l'applicazione in debug con entrambe le caselle di controllo per Debug/Eccezioni/Common Language Runtime Exceptions set.

+0

già fatto, controllo tutto il tipo di casella per eccezione possibile e ancora nulla. – user1107078

0

Provare a mettere un blocco try/catch attorno al codice in backgroundWorker1_DoWork e inserire un punto di interruzione nella clausola catch, dovresti essere in grado di rilevare l'eccezione.

+0

è la prima cosa che ho fatto ma. Arresto anomalo del runtime .net non genera eccezioni. – user1107078

2

Da Microsoft Site: A partire da .NET Framework versione 4, questo evento non viene generato per eccezioni che corrompono lo stato del processo, quali overflow dello stack o violazioni dell'accesso, a meno che il gestore eventi non sia critico per la sicurezza e ha l'attributo HandleProcessCorruptedStateExceptionsAttribute. Forse dovresti provare a aggiungere quell'attributo.

Per Application.ThreadException, dalla Microsoft Sito di nuovo: "a garantire che non attivazioni di questo evento sono mancati, è necessario collegare un gestore prima di chiamare Application.Run". Nel codice non è chiaro se si allega il gestore prima di chiamare Application.Run.

Inoltre - si può decidere di avere il blocco "generico" try fermo sui luoghi che possono essere chiamare codice non gestito:

try { 
// Code goes here 
} 
catch { //Unmanaged exceptions will be caught here as well. 

} 

try { 
// Code goes here. 
} 
catch(Exception ex){ // only managed exceptions are caught, avoid that in your case. 
} 

Il primo sarà intercettare le eccezioni non gestite, mentre il secondo non lo faranno.

Problemi correlati