帮我看看这个VB.net,Invoke老是报错,怎么修改?
发布网友
发布时间:2022-05-16 20:51
我来回答
共1个回答
热心网友
时间:2024-03-02 00:47
(补充:)
Private Sub myJobManager_Stopped(ByVal sender As Object, ByVal e As
CogJobManagerActionEventArgs)
If InvokeRequired Then
Dim myDel As New myJobManagerDelegate(AddressOf myJobManager_Stopped)
Dim eventArgs() As Object = {sender, e}
Invoke(myDel, eventArgs) '程序在这里报错
Return
End If
RunOnceButton.Enabled = True
RunContCheckBox.Enabled = True
End Sub
Private Sub RunContCheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RunContCheckBox.CheckedChanged
If (RunContCheckBox.Checked) Then
Try
RunOnceButton.Enabled = False
myJobManager.RunContinuous()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Else
Try
RunContCheckBox.Enabled = False
myJobManager.Stop()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub
Private Sub myJobManager_UserResultAvailable(ByVal sender As Object, ByVal e As
CogJobManagerActionEventArgs)
If InvokeRequired Then
Dim myDel As New myJobManagerDelegate(AddressOf myJobManager_UserResultAvailable)
Dim eventArgs() As Object = {sender, e}
Invoke(myDel, eventArgs) '程序在这里报错
Return
End If
Dim topRecord As Cognex.VisionPro.ICogRecord = myJobManager.UserResult
RunStatusTextBox.Text = _
topRecord.SubRecords("UserResultTag").Content & ": " _
& topRecord.SubRecords("JobName").Content & " --> " _
& topRecord.SubRecords("RunStatus").Content.ToString
Dim tmpRecord As Cognex.VisionPro.ICogRecord
tmpRecord = topRecord.SubRecords("ShowLastRunRecordForUserQueue")
tmpRecord = tmpRecord.SubRecords("LastRun")
tmpRecord = tmpRecord.SubRecords("CogFixtureTool1.OutputImage")
CogRecordDisplay1.Record = tmpRecord
CogRecordDisplay1.Fit(True)
End Sub
End Class
××××××××××××××××××××××××
‘’报错信息:
未处理 System.IndexOutOfRangeException
Message="Index was outside the bounds of the array."
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method,
Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at WindowsApplication1.Form1.myJobManager_UserResultAvailable(Object sender,
CogJobManagerActionEventArgs e) in D:\My Documents\Visual Studio 2005
\Projects\WindowsApplication2\WindowsApplication2\Form1.vb:line 88
at Cognex.VisionPro.QuickBuild.CogJobManager.OnUserResultAvailable()
at Cognex.VisionPro.QuickBuild.CogJobManager.UserQueueEnqueue(ICogRecord record)
at
Cognex.VisionPro.QuickBuild.Implementation.Internal.CogJobControl.IndependentProcessingThrea
d()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup
(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,
ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,
ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
(完)