private void f()
{
Action<string> action = WriteLogToFile;
AsyncCallback callBack = LogCallBack;
action.BeginInvoke("Hello world!", callBack, action);
}
private void WriteLogToFile(string message)
{
Monitor.Enter(locker);
string formattedLog = Write(message);
try
{
SendEmailNotifications(formattedLog);
}
catch (InvalidOperationException)
{
...
}
Monitor.Exit(locker);
}
private static void LogCallBack(IAsyncResult r)
{
if (r.IsCompleted)
{
((Action<String>) r.AsyncState).EndInvoke(r);
}
}
答案 0 :(得分:0)
这是一个Windows窗体应用程序吗?
确保您订阅了threadexception事件。
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.threadexception.aspx