帮助关闭应用程序上的错误消息 [英] Help with error message on Application close

查看:58
本文介绍了帮助关闭应用程序上的错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



应用程序关闭时,我有时会从Form'的Dispose方法中得到以下错误:

----------- --------------------------------------

未处理的例外情况在System.windows.forms.dll中输入''System.InvalidOperationException''



附加信息:在执行CreateHandle()时无法调用Dispose()。

--------------------------------------------- ----

如何找出调用CreateHandle()的内容?


这是表单中的Dispose:

///< summary>

///清理正在使用的所有资源。

///< / summary>

protected override void Dispose(bool disposing)

{

m_Logger.StopLogging();

m_Logger.CloseConnection();

if(处理)

{

if(components!= null)

{

components .Dispose();

}

}

base.Di spose(disposing);

}


我在m_Logger中有一个串行连接,但我关闭连接并且

调用CloseHandle的()。我根本不打电话给CreateHandle。如果我打开串行连接,我打电话给

CreateFile,但不是来自Close()。当我

关闭应用程序时,我没有打开连接。


谢谢,

jim

I sometimes get the following error from my Form''s Dispose Method when the
application is closing:
-------------------------------------------------
An unhandled exception of type ''System.InvalidOperationException'' occurred
in system.windows.forms.dll
Additional information: Cannot call Dispose() while doing CreateHandle().
-------------------------------------------------
How do I find out what is calling CreateHandle()?

Here is the Dispose from the form:
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
m_Logger.StopLogging();
m_Logger.CloseConnection();
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

I have a serial connection in m_Logger, but I close the connection and that
calls CloseHandle(). I don''t call CreateHandle at all. I do call
CreateFile if I''m opening a serial connection, but not from Close(). When I
close the app I am not in the process of opening a connection.

Thanks,
jim

推荐答案

Jim,


例外是否没有详细说明发生这种情况的原因?

尝试在可疑区域周围放置try / catch语句,然后放置

点的Debug.Write语句来帮助解决问题。例如,

是m_Logger.StopLogging()或

m_Logger.CloseConnection()中引发的异常?


虽然这个可能不是您的问题的原因,所有托管代码应该包含在if(disposing)中的所有内容中。块。你应该不会尝试在一个终端用户的通话中访问托管代码(即处理时为

false)。


菲尔......


" Jim H" <无**** @ jimsaccount.com>在留言中写道

新闻:e9 ************** @ TK2MSFTNGP09.phx.gbl ...
Jim,

Does the exception not give details as to exactly where this is occurring?
Try placing try/catch statement around suspect areas and place either break
points of Debug.Write statements to help home into the problem. For example,
is the exception raised within m_Logger.StopLogging() or
m_Logger.CloseConnection()?

Whilst this may not be the cause of your problem, all managed code should be
contained inside the "if (disposing)" block. You should make no attempt to
access managed code during a call from a finializer (ie when disposing is
false).

Phil...

"Jim H" <no****@jimsaccount.com> wrote in message
news:e9**************@TK2MSFTNGP09.phx.gbl...
我有时会得到以下内容
申请结束时,我的表格的处理方法出错:
--------------------------- ----------------------
在system.windows.forms中发生了'System.InvalidOperationException'类型的未处理异常。 dll
附加信息:在执行CreateHandle()时不能调用Dispose()。
--------------------------- ----------------------
如何找出调用CreateHandle()的内容?

这是Dispose从表格中:
///< summary>
///清理正在使用的所有资源。
///< / summary>
protected override void Dispose( bool处理)
m_Logger.StopLogging();
m_Logger.CloseConnection();
if(disposing)
{
if(components!= null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}

我在m_Logger中有一个串口连接,但是我关闭了连接并打了电话CloseHandle的()。我根本不打电话给CreateHandle。如果我打开串行连接,我会打电话给
CreateFile,但不是来自Close()。当我关闭应用程序时,我不在打开连接。

谢谢,
jim
I sometimes get the following error from my Form''s Dispose Method when the
application is closing:
-------------------------------------------------
An unhandled exception of type ''System.InvalidOperationException'' occurred
in system.windows.forms.dll
Additional information: Cannot call Dispose() while doing CreateHandle().
-------------------------------------------------
How do I find out what is calling CreateHandle()?

Here is the Dispose from the form:
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
m_Logger.StopLogging();
m_Logger.CloseConnection();
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

I have a serial connection in m_Logger, but I close the connection and
that calls CloseHandle(). I don''t call CreateHandle at all. I do call
CreateFile if I''m opening a serial connection, but not from Close(). When
I close the app I am not in the process of opening a connection.

Thanks,
jim


应用程序在base.Dispose()上以绿线停止。因为

错误消息说无法调用Dispose,它必须在base.Dispose()或

Components.Dispose()中。这些都不是我的代码。它并不总是发生,所以我会试一试......抓住每一个陈述并看看

哪一个抓住它。


jim


" Phil Jenson" <博士** @ jenson.co.uk.nospam>在消息中写道

新闻:O4 ************** @ TK2MSFTNGP11.phx.gbl ...
The application stops with a green line on base.Dispose(). Because the
error message says cannot call Dispose it must be in base.Dispose() or
Components.Dispose(). Neither of which are my code. It doesn''t always
happen so I''ll put a try...catch around each of those statements and see
which one catches it.

jim

"Phil Jenson" <Ph**@jenson.co.uk.nospam> wrote in message
news:O4**************@TK2MSFTNGP11.phx.gbl...
Jim,
异常是否没有详细说明发生这种情况的原因?
尝试在可疑区域周围放置try / catch语句并放置Debug.Write语句的断点以帮助进入问题。例如,是m_Logger.StopLogging()或
m_Logger.CloseConnection()中引发的异常吗?

虽然这可能不是您的问题的原因,但所有托管代码应该包含在if(disposing)中。块。你不应该尝试在一个终端用户的通话中访问托管代码(即当处置
是假的时候)。

菲尔...
Jim H <无**** @ jimsaccount.com>在消息中写道
新闻:e9 ************** @ TK2MSFTNGP09.phx.gbl ...
Jim,

Does the exception not give details as to exactly where this is occurring?
Try placing try/catch statement around suspect areas and place either
break points of Debug.Write statements to help home into the problem. For
example, is the exception raised within m_Logger.StopLogging() or
m_Logger.CloseConnection()?

Whilst this may not be the cause of your problem, all managed code should
be contained inside the "if (disposing)" block. You should make no attempt
to access managed code during a call from a finializer (ie when disposing
is false).

Phil...

"Jim H" <no****@jimsaccount.com> wrote in message
news:e9**************@TK2MSFTNGP09.phx.gbl...
我有时会从表单中收到以下错误
申请结束时的处理方法:
------------------------------- ------------------
system.windows.forms.dll中发生了未处理的System.InvalidOperationException类型的异常。
>附加信息:在执行CreateHandle()时无法调用Dispose()。
------------------------------- ------------------
如何找出调用CreateHandle()的内容?

以下是表单中的Dispose:
///< summary>
///清理正在使用的所有资源。
///< / summary>
protected override void Dispose(bool disposing)
{
m_Logger.StopLogging();
m_Logger.CloseConnection();
if(disposing)
{
if(components!= null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}

我在m_Logger中有一个串口连接,但是我关闭了连接并打了电话CloseHandle的()。我根本不打电话给CreateHandle。如果我打开串口连接,我会打电话给
CreateFile,但不是来自Close()。
当我关闭应用程序时,我不在打开连接。
<谢谢,
jim
I sometimes get the following error from my Form''s Dispose Method when the
application is closing:
-------------------------------------------------
An unhandled exception of type ''System.InvalidOperationException''
occurred in system.windows.forms.dll
Additional information: Cannot call Dispose() while doing CreateHandle().
-------------------------------------------------
How do I find out what is calling CreateHandle()?

Here is the Dispose from the form:
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
m_Logger.StopLogging();
m_Logger.CloseConnection();
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

I have a serial connection in m_Logger, but I close the connection and
that calls CloseHandle(). I don''t call CreateHandle at all. I do call
CreateFile if I''m opening a serial connection, but not from Close().
When I close the app I am not in the process of opening a connection.

Thanks,
jim




Jim,


看了Form / Control类中的代码后我相信

这种异常只能是因为从

不同的线程调用Dispose而导致的形式使用的(尽管我不可能确定知道的b $ b)。你在使用任何异步事件或线程吗?

从哪里调用Form.Dispose()方法?


你能发布堆栈跟踪吗?例外。


Phil ...


" Jim H" <无**** @ jimsaccount.com>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP15.phx.gbl ...
Jim,

Having had a look at the code within the Form/Control classes I believe that
this exception can only occur as a result of Dispose being called from a
different thread to that used by the form (although it not possible for me
to know for certain). Are you using any asynchronous events or threading?
From where are you calling the Form.Dispose() method?

Could you post the stack trace from the exception.

Phil...

"Jim H" <no****@jimsaccount.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
申请表在base.Dispose()上以绿线停止。因为
错误消息说不能调用Dispose它必须在base.Dispose()或
Components.Dispose()中。这些都不是我的代码。它并不总是发生,所以我会试一试......抓住每一个陈述并看看哪一个抓住它。

jim

Phil Jenson <博士** @ jenson.co.uk.nospam>在消息中写道
新闻:O4 ************** @ TK2MSFTNGP11.phx.gbl ...
The application stops with a green line on base.Dispose(). Because the
error message says cannot call Dispose it must be in base.Dispose() or
Components.Dispose(). Neither of which are my code. It doesn''t always
happen so I''ll put a try...catch around each of those statements and see
which one catches it.

jim

"Phil Jenson" <Ph**@jenson.co.uk.nospam> wrote in message
news:O4**************@TK2MSFTNGP11.phx.gbl...
Jim,
该例外是否没有详细说明发生这种情况的确切位置?尝试在可疑区域周围放置try / catch语句并放置Debug.Write语句的断点以帮助回到问题中。例如,
m_Logger.StopLogging()或m_Logger.CloseConnection()中引发的异常是什么?

虽然这可能不是您的问题的原因,但所有托管代码都应
被包含在if(disposing)中。块。你应该在没有尝试访问托管代码的过程中(即当处理错误时)。

菲尔...
Jim H <无**** @ jimsaccount.com>在消息中写道
新闻:e9 ************** @ TK2MSFTNGP09.phx.gbl ...
Jim,

Does the exception not give details as to exactly where this is
occurring? Try placing try/catch statement around suspect areas and place
either break points of Debug.Write statements to help home into the
problem. For example, is the exception raised within
m_Logger.StopLogging() or m_Logger.CloseConnection()?

Whilst this may not be the cause of your problem, all managed code should
be contained inside the "if (disposing)" block. You should make no
attempt to access managed code during a call from a finializer (ie when
disposing is false).

Phil...

"Jim H" <no****@jimsaccount.com> wrote in message
news:e9**************@TK2MSFTNGP09.phx.gbl...
我有时会从表单中收到以下错误应用程序关闭时的处理方法:
------------------------------- ------------------
system.windows.forms.dll中发生了未处理的System.InvalidOperationException类型的异常。
>附加信息:在执行
CreateHandle()时无法调用Dispose()。
--------------------------- ----------------------
如何找出调用CreateHandle()的内容?

这是Dispose从表格中:
///< summary>
///清理正在使用的所有资源。
///< / summary>
protected override void Dispose( bool处理)
m_Logger.StopLogging();
m_Logger.CloseConnection();
if(disposing)
{
if(components!= null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}

我在m_Logger中有一个串口连接,但是我关闭了连接并打了电话CloseHandle的()。我根本不打电话给CreateHandle。如果我打开串口连接,我会打电话给
CreateFile,但不是来自Close()。
当我关闭应用程序时,我不在打开连接。
<谢谢,
jim
I sometimes get the following error from my Form''s Dispose Method when
the application is closing:
-------------------------------------------------
An unhandled exception of type ''System.InvalidOperationException''
occurred in system.windows.forms.dll
Additional information: Cannot call Dispose() while doing
CreateHandle().
-------------------------------------------------
How do I find out what is calling CreateHandle()?

Here is the Dispose from the form:
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
m_Logger.StopLogging();
m_Logger.CloseConnection();
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

I have a serial connection in m_Logger, but I close the connection and
that calls CloseHandle(). I don''t call CreateHandle at all. I do call
CreateFile if I''m opening a serial connection, but not from Close().
When I close the app I am not in the process of opening a connection.

Thanks,
jim





这篇关于帮助关闭应用程序上的错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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