应用程序退出时出现System.NullException [英] System.NullException on application exit

查看:88
本文介绍了应用程序退出时出现System.NullException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Application.Exit时,我在Windows窗体项目(.NET 2.0/Windows 7/Visual Studio 2010)中收到此错误

When using Application.Exit I am getting this error on a Windows forms project (.NET 2.0 / Windows 7 / Visual Studio 2010 )

未处理System.NullReferenceException
  Message =对象引用未设置为对象的实例.
 来源= System.Management
  StackTrace:
     在System.Management.IWbemServices.CancelAsyncCall_(IWbemObjectSink pSink)中
     在System.Management.SinkForEventQuery.Cancel()
     在System.Management.ManagementEventWatcher.Stop()处
     在System.Management.ManagementEventWatcher.Finalize()处
  InnerException:

System.NullReferenceException was unhandled
  Message=Object reference not set to an instance of an object.
  Source=System.Management
  StackTrace:
       at System.Management.IWbemServices.CancelAsyncCall_(IWbemObjectSink pSink)
       at System.Management.SinkForEventQuery.Cancel()
       at System.Management.ManagementEventWatcher.Stop()
       at System.Management.ManagementEventWatcher.Finalize()
  InnerException:
~

现在,我确实在我的应用程序中使用System.Management.ManagementEventWatcher,但此表单甚至尚未加载.因此,在应用程序退出时,我找不到对此的任何引用.我该如何解决?它没有显示任何行号

Now I do use System.Management.ManagementEventWatcher within my application, but this form hasn't even loaded yet. So I can't find I have any reference to this at the time of application exit. How do I troubleshoot this? It doesn't show me any line number assosciated with the exit.

推荐答案

您好

使用尝试并捕获"块并找到这样的错误行

Use a Try and Catch Block and find the line of error like this

尝试

{

 

 

}

catch(异常例外)

catch(Exception ex)

{

MessageBox.Show(ex.StackTrace);

MessageBox.Show(ex.StackTrace);

}

这将使源代码行出现错误

This is will give the source code line of error 


这篇关于应用程序退出时出现System.NullException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆