我在Visual Studio中创建了一个TaskBar应用程序,它在系统托盘内最小化,并根据数据库更改向用户显示通知.每当分配给用户的新任务时,他将在系统托盘上通知,如气球弹出窗口.但是,每当应用程序平均运行15个小时时,我的应用程序崩溃并显示内存不足异常.所以我有一些问题请回答.
我的申请图片: 
回答你的4个问题:
1:您可以拦截My.Application.Startup事件以添加一些异常处理代码.请注意,Startup事件处理程序的代码存储在ApplicationEvents.vb文件中,默认情况下该文件是隐藏的.下面是一些C#代码(在VB中几乎完全相同),它们将设置您的异常处理程序:
// Event handler for handling UI thread exceptions.
Application.ThreadException += 
    new ThreadExceptionEventHandler(App_UiThreadException);
// Force all Windows Forms errors to go through our handler.
// NB In .NET 4, this doesn't apply when the process state is corrupted.
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
// Event handler for handling non-UI thread exceptions. 
AppDomain.CurrentDomain.UnhandledException += new 
    UnhandledExceptionEventHandler(App_NonUiThreadException);
// Run the application.
2:您可以使用免费的CLR Profiler来检查内存使用情况.
3:如果要查看程序将如何处理它,您可以自己抛出OutOfMemory异常.
4:一个有用的资源是Debug Leaky Apps.另一个是识别CLR内存泄漏.
| 归档时间: | 
 | 
| 查看次数: | 2175 次 | 
| 最近记录: |