我有一个VB.NET winforms解决方案,并且想要添加标准应用程序异常处理程序 - Application.ThreadException
和AppDomain.CurrentDomain.UnhandledException
。当Sub Main不可访问时,在VB.NET中捕获ThreadingException
我有以下代码from MSDN
' Starts the application. '
<SecurityPermission(SecurityAction.Demand, Flags:=SecurityPermissionFlag.ControlAppDomain)> _
Public Shared Sub Main()
' Add the event handler for handling UI thread exceptions to the event. '
AddHandler Application.ThreadException, AddressOf ErrorHandlerForm.Form1_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. '
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf CurrentDomain_UnhandledException
' Runs the application. '
Application.Run(New ErrorHandlerForm())
End Sub
我怎样才能做到这一点在VB.NET的时候我没有存取权限的Sub Main()
方法?
是当“启用应用程序框架”我的解决方案属性中启用的
将前三行代码复制到您可以访问的第一个方法调用中。这里会出现一个小应急窗口,但你赢了一些,你输了一些。 – 2011-03-14 14:58:33
@Mr。失望:看到与RoadWarrior波纹管相同的评论... – serhio 2011-03-14 15:33:59
我明白了......看到我的答案。 – 2011-03-14 15:41:57