简体   繁体   English

System.ObjectDisposedException

[英]System.ObjectDisposedException

I am running some windows application and it's working for few days then stop working with no error. 我正在运行一些Windows应用程序,它工作了几天然后停止工作没有错误。 Now i found in event viewer this error. 现在我在事件查看器中发现了这个错误。 Maybe anyone have any idea what can cause this error? 也许有人知道什么会导致这个错误?

Event Type: Error 事件类型:错误

Event Source: .NET Runtime 2.0 Error Reporting Event 事件源:.NET Runtime 2.0错误报告事件

Category: None 类别:无

Event ID: 5000 事件ID:5000

Date: 30.10.2010 日期:2010年10月30日

Time: 21:58:57 时间:21:58:57

User: N/A 用户:N / A.

Computer: SERVER-PROD 电脑:SERVER-PROD

Description: EventType clr20r3, P1 program.exe, P2 1.0.0.0, P3 4cca7ed1, P4 mscorlib, P5 2.0.0.0, P6 4be90358, P7 1164, P8 0, P9 system.objectdisposedexception, P10 NIL. 描述:EventType clr20r3,P1 program.exe,P2 1.0.0.0,P3 4cca7ed1,P4 mscorlib,P5 2.0.0.0,P6 4be90358,P7 1164,P8 0,P9 system.objectdisposedexception,P10 NIL。

ObjectDisposedException is: ObjectDisposedException是:

The exception that is thrown when an operation is performed on a disposed object. 在已处置对象上执行操作时引发的异常。 ( source ) 来源

In other words, if an instance of a class that implements the IDisposable interface is disposed -- either explicitly by a call to Dispose() or implicitly, such as if it appears in a using statement or otherwise -- any attempts to call methods on the object will raise the exception above. 换句话说,如果实现了实现IDisposable接口的类的实例 - 通过调用Dispose()显式地或者隐式地(例如,如果它出现在using语句中或其他方式) - 任何尝试调用方法的方法该对象将引发上述异常。

As with most debugging problems, it's very difficult to say what is causing yours without actually looking at the code and running it in a debugger. 与大多数调试问题一样,如果不实际查看代码并在调试器中运行它,很难说是什么导致了您的问题。 You say that the program crashes with ObjectDisposedException after running for a few days. 你说在运行几天后程序崩溃了ObjectDisposedException。 In my experience, this is usually means one of two things: 根据我的经验,这通常意味着两件事之一:

  1. There is some very unusual code path which, when taken, always causes a crash 有一些非常不寻常的代码路径,一旦采取,总会导致崩溃
  2. A race condition exists between threads in your program. 程序中的线程之间存在竞争条件 Thus, the crash appears unpredictably and may be difficult to reproduce 因此,崩溃看起来不可预测并且可能难以再现

My advice to you is to start the program in the debugger, and leave it running until the exception is thrown. 我的建议是在调试器中启动程序,并保持运行直到抛出异常。 Then you can come back here and provide us with the relevant code, stack trace, debug output, etc. 然后你可以回到这里并向我们提供相关代码,堆栈跟踪,调试输出等。

Something is accessing an object that has been disposed. 有东西正在访问已被处置的对象。 Often this can happen if you have multi-threading on a form. 如果您在表单上有多线程,通常会发生这种情况。 You start the backgroundworker/thread/timer, and then dispose the form. 启动backgroundworker / thread / timer,然后处理表单。 When the backgroundworker/thread/timer tries to update the form in some way, you get this exception. 当backgroundworker / thread / timer尝试以某种方式更新表单时,您会收到此异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM