Execution Engine Error

Has anyone else out there had this error I get it when I exit the application that I wrote.

An unhandled exception of type 'System.ExecutionEngineException' occurred in mscorlib.dll

According the wise ones in Redmond, this error should never happen. Unfortunately, I am getting about 70% of the time when I close the application. I've found that if I comment out a certain line, the error goes away. Unfortunately, the line is one that I need to get the code right. I'll post the code here in a minute.

What this is supposed to do is fill a series of custom (number only) text boxes with readings from the sensors on a machine that we have. It does do that on form load, no problem. The problem comes when I exit this form. That's when I get the error. If I comment out the line about the syncronizing object (third line in Form1_Load) the error goes away, but the readings are sketchy. That won't work.

I could really use some help with this.

Thanks

Joe White

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

dio.closenozzles("DAQPad")

dio.closeport("DAQpad")

areader.SynchronizingObject = Me

callback = New AsyncCallback(AddressOf analogInCallback)

areader.BeginReadMultiSample(100, callback, Nothing)

End Sub

Private Sub analogInCallback(ByVal ar As IAsyncResult)

Try

'Stop reading and pass the contents of the buffer

'to the array using the async callback

data = areader.EndReadMultiSample(ar)

NozzleTemp.Text = data(0, data.GetUpperBound(1))

MeterTemp.Text = data(1, data.GetUpperBound(1))

RH.Text = data(2, data.GetUpperBound(1))

Absolute.Text = data(3, data.GetUpperBound(1))

MNDiff.Text = data(4, data.GetUpperBound(1))

Vacuum.Text = data(5, data.GetUpperBound(1))

MeterDiff.Text = data(6, data.GetUpperBound(1))

RevSensor.Text = data(7, data.GetUpperBound(1))

areader.BeginReadMultiSample(100, callback, Nothing)

Array.Clear(data, 0, data.Length)

Catch ex As Exception

MessageBox.Show(ex.Message)

ai.Dispose()

End Try

End Sub



Answer this question

Execution Engine Error

  • samdalil

    I'd guess that the analogInCallback() runs after the .NET runtime has shut down. Look for a method of the areader object that lets you stop reading (something like "EndReadMultiSample") and call that in your Form1_Close event handler.
  • Lie

    It sounds like you're using a 3rd party I/O library. It is obviously using a separate thread to do the reading of the analog I/O, that's why you have to use the SynchronizingObject property and get scrambled readings when you don't. This thread probably calls analogInCallback() AFTER the form was unloaded. The .NET runtime sees this and bombs with ExecutionEngineException. This is not a .NET problem but a problem with the I/O library. Contact the vendor of this library or look through code samples in the documentation for this library to find out how to properly shut down the thread.

    The onReadCompleted() method sounds like an event to get samples without using a separate thread. Again, look for code samples or contact the vendor to find out how to use it.



  • RGE

    Here is the code I added. I'm still getting the same error at random places. Sometimes I get it at the exit of this form, sometimes at the exit of other forms that have no data acquistition in them. However, it is always at the exit of a form. I'm stumped. The thing that really sucks is that according to Microsoft, this is NEVER supposed to happen. That's not a lot of comfort right now though.

    If running = True Then

    myResult = New AsyncCallback(AddressOf onCompletedRead)

    'aitask.Stop()

    aitask.Dispose()

    running = False

    End If

    Public Sub onCompletedRead(ByVal asyncResult As IAsyncResult)

    Array.Clear(data, 0, data.Length)

    data = reader.EndReadMultiSample(myResult)

    aitask.Stop()

    End Sub


  • Execution Engine Error