问题描述
我有一个问题,我的WinApp表格程序,它包含一个选项卡控件与WebBrowser控件DLL(GeckoFX)。
I have a problem with My WinApp Form program which contain a tab Control with WebBrowser control DLL (GeckoFX).
我的应用程序在运行接近没有任何异常或任何东西。几分钟或最多10分钟后后,它可能发生。在Visual Studio中我看到code 0任何应用程序终止。
My application while running close without any exception or anything. It could happen after few minutes or max after 10 min. In visual studio I see application terminate with code 0. Anything.
在Program.cs中我抓住这一切未处理excpetion
In program.cs I catch all this unhandled excpetion
` // 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);`
我已经检查Windows事件记录任何错误,但它的清洁。就像程序终止很好。我不知道这是否是壁虎DLL的错,但我不这么认为。
I already Check in Windows Event logger for any error but it's clean. Just like the Program is terminated well. I don't know if it's Gecko DLL fault but I don't think so.
我用HttpWebRequest的下载,其中包含一些URL列表。
I use httpWebRequest to download a list which contains some URL.
然后我用一个的BackgroundWorker
其内容的URL列表,并调用addTab委托方法睡眠一点,直到页面加载,并继续与其他AddTab调用。
Then I use a Backgroundworker
which read the list of the URL , and invoke addTab Delegate Method Sleep a bit until page is loaded and continue with other AddTab Invoke.
在列表为空我检查,如果在DOM页面是有一定的字符串,然后在的BackgroundWorker
完成我关闭所有标签页和处置他们,我点击Button1的这启动 Backgroundworker1.asyncall();
When the list is empty I check if in the DOM page there is a certain string Then in Backgroundworker
Complete I Close All Tabs and Dispose them and I click on button1 which start the Backgroundworker1.asyncall();
是不是有什么毛病我的逻辑是什么?我会后code也一样,我需要它太长,但我真的需要明白的地方可能是终止我的应用程序中的错误。如果有人能帮助我,看看它为什么崩溃没有任何错误或任何东西我都会AP preciate了。
Is there something wrong with my Logic? I will post code too, I need that it's too long but I really need understand where could be the error that terminate my application. If someone can help me to see why it crash without any error or anything I will appreciate that.
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
}
}
推荐答案
从微软网站:与.NET Framework 4版开始,这一事件不会引发例外的过程中,如腐败国家堆栈溢出或访问违规,除非该事件处理程序是安全关键和具有HandleProcessCorruptedStateExceptionsAttribute属性。的也许你应该尝试addding的属性。
From Microsoft Site: Starting with the .NET Framework version 4, this event is not raised for exceptions that corrupt the state of the process, such as stack overflows or access violations, unless the event handler is security-critical and has the HandleProcessCorruptedStateExceptionsAttribute attribute.Maybe you should try addding that attribute.
有关Application.ThreadException,从Microsoft网站再次:的要保证不激活此事件被错过了,你叫Application.Run之前,您必须将处理程序。的在您的code,如果你调用Application.Run前将其处理程序不明确。
For Application.ThreadException, from the Microsoft Site again:"To guarantee that no activations of this event are missed, you must attach a handler before you call Application.Run."In your code it is not clear if you attach the handler before calling Application.Run.
另外 - 你可能希望有通用try catch块就可以被调用非托管code处:
Also - you may want to have the "generic" try catch block on places that may be calling unmanaged code:
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.
}
第一个将捕获的非托管异常,而第二个则不会。
The first will catch unmanaged exceptions while the second will not.
这篇关于WinApp表崩溃没有任何错误或异常的.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!