Jump to content
The simFlight Network Forums

Recommended Posts

Posted (edited)

Hi!

 

I'm working on an external application for FS9, FSX and P3D. What is generally the best way to detect when FS is closed or crashes?

 

Even

Edited by Even92LN
Posted

Hi Even,

 

The only way to know this is to catch the errors produced when the FSUIPC Process() call fails.

 

If you are using my DLL the sample program that comes with it shows how to do this.  Look at the code on the tick event for Timer1.  You'll see a try/catch block where it catches the FSUIPCException from the Process() call which means FSX/9 has unloaded or crashed.  It then closes the connection, tells the user, and lights a button so the user can try reconnecting.

 

 

If you're not using my DLL then it will depend on the programming language you are using.  You would also be in the wrong sub-forum :-) so I recommend you post again in the main support forum (above this one) and include the language you are using.

 

Paul

  • 1 month later...
Posted

Hi,

 

I am unable to detect a crash and my app continues to run normally on the client pc when the fsx server disconnects and I am connecting via WideClient. Obviously I don't get any new data just the same data from the last read each time my timer ticks.

Even when WideClient eventually times out and gives the 'waiting for a connection' message my app still continues to read the offsets as though the connection is still there.

Any ideas how to trap this please? I've had a quick read of the WideClient manual but can't seem to locate a relevent parameter.

 

thanks

Graham

Posted

I am unable to detect a crash and my app continues to run normally on the client pc when the fsx server disconnects and I am connecting via WideClient. Obviously I don't get any new data just the same data from the last read each time my timer ticks.

Even when WideClient eventually times out and gives the 'waiting for a connection' message my app still continues to read the offsets as though the connection is still there.

Any ideas how to trap this please? I've had a quick read of the WideClient manual but can't seem to locate a relevent parameter.

 

Unfortunately, WideClient doesn't really know that FSX has crashed. It will be constantly trying to reconnect.

 

There are ways you can detect the disconnection.  First there's offset 333C. Bit 1 there should get reset to 0 on a disconnection. But in case it is a temporary interruption, best to check that it stays that way a while. Second, there's the FSUIPC activity counter at offset 337E. Just check that this changes within reasonable times.

 

You could also check things like the elapsed time offset, to see that changing, but the above two should be okay.

 

Regards

Pete

Posted

Thanks Pete, I've used the 333C offset and works fine.

 

Code below for anyone interested (vb.net) though you'll need to modify for own use

    Private Shared fsWideFSRunning As Offset(Of UShort) = New FSUIPC.Offset(Of UShort)("widefs", &H333C)
    Public Shared WideFSRunning As Boolean 

    Public Shared Sub getfsWideFSRunning()

        FSUIPCConnection.Process("widefs")
        WideFSRunning = fsWideFSRunning.Value

    End Sub

then check like this - I have this code at the start of my timer section

        SimulatorEvents.getfsWideFSRunning()

        If SimulatorEvents.WideFSRunning = False Then
            Me.Timer_Seconds.Enabled = False 'pause polling'
            Dim msg = MessageBox.Show("The connection to Flight Sim has been lost, retry connection?", "WideFS connection lost", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
            If msg = DialogResult.Yes Then
                Me.Timer_Seconds.Enabled = True
                Exit Sub 'exit sub and retry on next poll count'
            Else
                Dim msg2 = MessageBox.Show("Abandon retry?", "Restart Application?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                If msg2 = DialogResult.Yes Then
                    'stop main timer and reset app'
                    Me.Timer_Seconds.Enabled = False
                    frmMain.ClearData()
                    Exit Sub
                Else 'no'
                    Me.Timer_Seconds.Enabled = True
                    Exit Sub 'exit sub and retry on next poll count'
                End If
            End If
        End If

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.