Jump to content
The simFlight Network Forums

Missing Exception


cknipe

Recommended Posts

Can't reproduce it now for some reason 🤯 Typical Murphy.

I've added the necessary code for a full stack and will revert if it happens again.  I think it may have been my PC though, but the exception should still be caught nonetheless.

I do believe it is your exception, as the source is your DLL and ~SystemOffsets~ aren't my variable.

I will revert back if / once it happens again and I have a full stack dump for you.

 

FYI, this is the code, fired by an Timer with a 10ms trigger

 Private sub FSUIPCProcess(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
    ' If we are not connected to the simulator, try to re-connect
    Try
      If SimConnected = False
        FSUIPCConnection.Open()
        If FSUIPCConnection.IsOpen
          SimConnected = True
        Else
          SimConnected = False
          Exit Sub
        End If
      Else
        FSUIPCConnection.Process
        Debug.Write("a")
      End If
    Catch ex As FSUIPCException
      If ex.FSUIPCErrorCode = FSUIPCError.FSUIPC_ERR_NOFS
        ' Can not connect to FSUIPC or WideFS, not running?
        SimConnected = False
      ElseIf ex.FSUIPCErrorCode = FSUIPCError.FSUIPC_ERR_OPEN
        ' We are apparently already connected
        SimConnected = True
      ElseIf ex.FSUIPCErrorCode = FSUIPCError.FSUIPC_ERR_NOTOPEN Or ex.FSUIPCErrorCode = FSUIPCError.FSUIPC_ERR_SENDMSG
        SimConnected = False
       Else
        Debug.WriteLine("EXCEPTION: " & ex.Message.ToString)
        Debug.WriteLine("    STACK: " & ex.StackTrace.ToString)
      End If
    Catch ex As Exception
      ' This is where the exception is caught
      Dim st As New StackTrace(ex, True)
      Debug.WriteLine("EXCEPTION: " & ex.Message.ToString)
      Debug.WriteLine("    STACK: " & st.ToString)
    End Try
  End sub

 

Link to comment
Share on other sites

Oh, and the exception occurs when:

- Initialize Timer to fire every 10ms;

- While True; Loop (just to ensure the timer fires)

Every 10ms, we now call Open() and/or Process() via the timer

Start, close, restart, the sim while the code is running.  

I *suspect*, either Open is executing, or Process is executing without the necessary variables in FSUIPCClient being initialized.

Link to comment
Share on other sites

Which timer are you using? Is it System.Timers.Timer? If so then I think the problem is that by running this code every 10ms you'll end up with multiple copies of FSUIPCProcess() being run in parallel on different threads.

This is the only thing I can think of that will cause this problem.

On my machine Open() takes over 100ms to run. So your timer will be starting about 10 threads all calling Open() before the first one finishes.

Each thread will be creating, processing and then deleting the ~systemoffsets~ group. So one thread will be trying to process this group but another has just deleted it.

If this is the case then here are some solutions:

1. Use a different timer when the connection is not open that uses a more realistic interval (e.g. 250ms) - or modify the tick interval of your existing timer.

2. If you are using WinForms and don't need your FSUIPCProcess() method running on a background thread you can use the Forms timer which will block each tick until the code on the previous tick has run completely. This will also block your UI though.

3. If you don't mind the timer not ticking at exactly 10ms you can set the timer to 'one-shot' mode with:

MyTimer.AutoReset = False

when you create it.

Then at the end of your FSUIPCProcess() method you can restart the timer and get another tick:

MyTimer.Start()

I hope one of those helps...

Paul

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.