Forms..NET 3.5 的 ShowDialog 和 Dispose 问题
ShowDialog and Dispose problem with Forms..NET 3.5
我正在修复现有 C# 项目中的一些错误。
我使用 Visual Studio 2008 和 3.5 .NET Framework。
该应用程序使用表单,并且应用程序的生命周期运行正常。我还没有做任何更改,但客户端最近开始出现奇怪的行为。
第一次可以毫无问题地使用该应用程序,但如果关闭一个表单而我们打开另一个表单,则此表单中的对象将被释放。
该代码适用于 PDA,我们有一个用于扫描的事件处理程序。
我认为这很奇怪,因为代码中的任何内容都没有更改。
也许这是一些框架错误?
我试图完全消除 Closing 事件的事件处理程序,但同样的错误发生了。
更改表单的处理方式。
表单创建
FormTEntreUbicaciones form = new FormTEntreUbicaciones(Movements.TREntreUbicaciones);
form.ShowDialog();
form.Dispose();
活动创建
if (Device.GetOSType2() == Device.OSType.WinMobile){
hDcd = new DecodeHandle(DecodeDeviceCap.Exists | DecodeDeviceCap.Barcode);
DecodeRequest reqType = (DecodeRequest)1 | DecodeRequest.PostRecurring;
dcdEvent = new DecodeEvent(hDcd, reqType, this);
dcdEvent.Scanned += new DecodeScanned(dcdEvent_Scanned);
}
表格应该是打开的,其中的所有对象都不应被释放
异常:
System.ObjectDisposedException was unhandled
Message="ObjectDisposedException"
ObjectName=""
StackTrace:
at System.Windows.Forms.Control.InvokeHelper(Delegate method, Boolean fSynchronous, Object[] rgobjArgs)
at System.Windows.Forms.Control.Invoke(Delegate method)
at Datalogic.API.DecodeEvent.WaitForScan()
有什么建议吗?
谢谢!
终于找到解决方法了
找出问题所在后,我发现 SCAN 事件一直保持活动状态。
我添加了关闭覆盖:
this.Closing += MyClosedHandler;
而MyClosedHandlerEvent如下:
//FIX MA 23.07.2019
protected void MyClosedHandler(object sender, EventArgs e)
{
if (dcdEvent.IsListening)
{
dcdEvent.StopScanListener();
}
if (hDcd != null)
{
hDcd.Dispose();
}
}
datalogic.api.dll 检测到问题。使用的PDA是Skorpio x3.
希望这对其他人有帮助!
我正在修复现有 C# 项目中的一些错误。 我使用 Visual Studio 2008 和 3.5 .NET Framework。
该应用程序使用表单,并且应用程序的生命周期运行正常。我还没有做任何更改,但客户端最近开始出现奇怪的行为。 第一次可以毫无问题地使用该应用程序,但如果关闭一个表单而我们打开另一个表单,则此表单中的对象将被释放。 该代码适用于 PDA,我们有一个用于扫描的事件处理程序。 我认为这很奇怪,因为代码中的任何内容都没有更改。 也许这是一些框架错误?
我试图完全消除 Closing 事件的事件处理程序,但同样的错误发生了。 更改表单的处理方式。
表单创建
FormTEntreUbicaciones form = new FormTEntreUbicaciones(Movements.TREntreUbicaciones);
form.ShowDialog();
form.Dispose();
活动创建
if (Device.GetOSType2() == Device.OSType.WinMobile){
hDcd = new DecodeHandle(DecodeDeviceCap.Exists | DecodeDeviceCap.Barcode);
DecodeRequest reqType = (DecodeRequest)1 | DecodeRequest.PostRecurring;
dcdEvent = new DecodeEvent(hDcd, reqType, this);
dcdEvent.Scanned += new DecodeScanned(dcdEvent_Scanned);
}
表格应该是打开的,其中的所有对象都不应被释放
异常:
System.ObjectDisposedException was unhandled
Message="ObjectDisposedException"
ObjectName=""
StackTrace:
at System.Windows.Forms.Control.InvokeHelper(Delegate method, Boolean fSynchronous, Object[] rgobjArgs)
at System.Windows.Forms.Control.Invoke(Delegate method)
at Datalogic.API.DecodeEvent.WaitForScan()
有什么建议吗? 谢谢!
终于找到解决方法了
找出问题所在后,我发现 SCAN 事件一直保持活动状态。
我添加了关闭覆盖:
this.Closing += MyClosedHandler;
而MyClosedHandlerEvent如下:
//FIX MA 23.07.2019
protected void MyClosedHandler(object sender, EventArgs e)
{
if (dcdEvent.IsListening)
{
dcdEvent.StopScanListener();
}
if (hDcd != null)
{
hDcd.Dispose();
}
}
datalogic.api.dll 检测到问题。使用的PDA是Skorpio x3.
希望这对其他人有帮助!