BeginInvoke——为什么当try块中的方法抛出InvalidOperationException异常时,catc
本文关键字:InvalidOperationException 异常 catc 为什么 try BeginInvoke 方法 | 更新日期: 2023-09-27 18:16:10
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);
}
}
这是一个windows窗体应用程序吗?
确保你订阅了threadexception事件。
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.threadexception.aspx