Better exception report.

This commit is contained in:
qianlifeng
2015-01-16 23:42:12 +08:00
parent 32e0074f26
commit 9d39b616f9
12 changed files with 98 additions and 80 deletions

View File

@@ -26,7 +26,12 @@
</root>
</log4net>
<runtime>
<!--http://stackoverflow.com/questions/186854/how-to-prevent-an-exception-in-a-background-thread-from-terminating-an-applicati-->
<!--http://stackoverflow.com/questions/186854/how-to-prevent-an-exception-in-a-background-thread-from-terminating-an-application-->
<!--prevent non-ui exception crash wox-->
<legacyUnhandledExceptionPolicy enabled="1"/>
</runtime>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
<supportedRuntime version="v4.0"/>
</startup>
</configuration>

View File

@@ -33,7 +33,6 @@ namespace Wox
base.OnStartup(e);
DispatcherUnhandledException += ErrorReporting.DispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle;
System.Windows.Forms.Application.ThreadException += ErrorReporting.ThreadException;
Window = new MainWindow();
CommandArgsFactory.Execute(e.Args.ToList());

View File

@@ -5,31 +5,38 @@ using System.Windows.Forms;
using System.Windows.Threading;
using Wox.Core.Exception;
using Wox.Infrastructure.Logger;
using MessageBox = System.Windows.MessageBox;
namespace Wox.Helper
{
public static class ErrorReporting
{
private static void Report(Exception e)
public static void Report(Exception e)
{
//if (Debugger.IsAttached) return;
if (Debugger.IsAttached) return;
Log.Error(ExceptionFormatter.FormatExcpetion(e));
new CrashReporter.CrashReporter(e).Show();
}
public static void UnhandledExceptionHandle(object sender, UnhandledExceptionEventArgs e)
{
Report((Exception)e.ExceptionObject);
//handle non-ui thread exceptions
App.Window.Dispatcher.Invoke(new Action(() =>
{
Report((Exception)e.ExceptionObject);
if (!(e.ExceptionObject is WoxException))
{
Environment.Exit(0);
}
}));
}
public static void DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
//handle ui thread exceptions
Report(e.Exception);
}
public static void ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
Report(e.Exception);
//prevent crash
e.Handled = true;
}
}
}

View File

@@ -353,28 +353,38 @@ namespace Wox
Dispatcher.DelayInvoke("ClearResults", i =>
{
// first try to use clear method inside pnlResult, which is more closer to the add new results
// and this will not bring splash issues.After waiting 30ms, if there still no results added, we
// and this will not bring splash issues.After waiting 100ms, if there still no results added, we
// must clear the result. otherwise, it will be confused why the query changed, but the results
// didn't.
if (pnlResult.Dirty) pnlResult.Clear();
}, TimeSpan.FromMilliseconds(100), null);
queryHasReturn = false;
var q = new Query(lastQuery);
PluginManager.Query(q);
Query(q);
BackToResultMode();
if (PluginManager.IsUserPluginQuery(q))
Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
{
Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
if (!queryHasReturn && originQuery == lastQuery)
{
if (!queryHasReturn && originQuery == lastQuery)
{
StartProgress();
}
}, TimeSpan.FromSeconds(0), lastQuery);
}
StartProgress();
}
}, TimeSpan.FromMilliseconds(150), lastQuery);
}, TimeSpan.FromMilliseconds(ShouldNotDelayQuery ? 0 : 200));
}
private void Query(Query q)
{
try
{
PluginManager.Query(q);
}
catch (Exception e)
{
StopProgress();
ErrorReporting.Report(e);
}
}
private void BackToResultMode()
{
pnlResult.Visibility = Visibility.Visible;