表格随机处理

Ale*_*ger 0 .net vb.net dispose winforms

Protected Overrides Sub LoadForm()
    MyBase.LoadForm()
    Try
        'StartProcess might be causing an error (error msg is issue with loading config, which would be incorrect)
        StartProcess()
        Dim D As New _Delegate(AddressOf SOPERATION)
        Me.Invoke(D)
        BusinessObject = New bConfig(Me)
        CType(BusinessObject, bConfig).LoadKeyValue()
    Catch ex As Exception
        MESSAGES.ShowMessage(MessageIndex.ErrInLoadConfigData, TitleIndex.LoadForm, MessageBoxButtons.OK, MessageBoxIcon.Information)
        StopProcess()
        EnableDisable(CurrentBillType)
    End Try
End Sub
Run Code Online (Sandbox Code Playgroud)

我可以在完全相同的条件下运行100次,看起来像是40次会因以下错误而崩溃:

"无法访问已处置的对象.对象名称:'frmImportExport'."

它要么死了

'within StartProcess()
    Dim __Delegate As New _Delegate(AddressOf StartProcess)
    Me.Invoke(__Delegate)
Run Code Online (Sandbox Code Playgroud)

要么

Dim D As New _Delegate(AddressOf SOPERATION)
Run Code Online (Sandbox Code Playgroud)

我知道在没有看到整个代码的情况下很难回答,但我不能为我的生活找出为什么有时这样做,有时在相同条件下不起作用.关于我能找到什么的任何想法?在我看到的任何地方都没有手动处理论坛,而且这个代码正在formload上执行.


附加信息:

StackTrace:"在ShiftBilling上的System.Windows.Forms.Control.Invoke(Delegate方法,Object [] args)中的System.Windows.Forms.Control.MarshaledInvoke(Control caller,Delegate方法,Object [] args,布尔同步). C:\ Users ....\BaseForm.vb中的BaseForm.StartProcess():C:\ Users\Alec\Work\Levelset\ShiftBillingSource\ShiftBilling_Source\JLRBilling\frmImportExport.vb中ShiftBilling.frmImportExport.LoadForm()的第138行:第66行"字符串

ShowProcess()的内容并不重要,但这里的代码是:

Protected Sub StartProcess()
    If Me.InvokeRequired Then
        Dim __Delegate As New _Delegate(AddressOf StartProcess)
        Me.Invoke(__Delegate)
    Else
        Validator.Clear()
        'If Me.MdiParent IsNot Nothing Then
        IsProcessRunning = True
        frmMain.ShowProgress()
        'CType(Me.MdiParent, frmMain).ShowProgress()
        EnableControls(False)
        'End If
    End If
End Sub
Run Code Online (Sandbox Code Playgroud)

如果失败,它永远不会到达EndProcess,因此不需要代码.

以下是单击链接以显示表单时执行的代码:

Private Sub ImportExportMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImportExportMenu.Click
    _frmimport = New frmImportExport
    If clickWindow(_frmimport.Text, _frmimport) = True Then Exit Sub
    _frmimport.Show()
    _frmimport.MdiParent = Me
    SetFormPosition(_frmimport)
End Sub
Run Code Online (Sandbox Code Playgroud)

它是一个要在主窗体中显示的子窗体.

值得注意的是,这是一个外包项目,我只有一天半的时间与之合作.

Han*_*ant 6

_frmimport.Show()
_frmimport.MdiParent = Me
Run Code Online (Sandbox Code Playgroud)

这可能是你问题的一部分.Show()方法强制创建Windows窗口,Handle属性获取值.然后,您可以更改MdiParent属性,该属性需要一个完全不同类型的窗口,即MDI子级.这需要Winforms来销毁Windows窗口并重新创建它.Handle值会发生变化.同时,您已经启动了一个使用表单的InvokeRequired和Invoke成员的线程.这要求Handle属性有效.这是一个关于是否会打击的时间问题.

交换这两个陈述.