Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hello,

 

I am facing a few issues when handling FSUIPC errors on a simulator crash/freeze. What i do when i receive an error from my FSUIPC thread is:

 

- Close FSUIPC connection;

- Enter a loop trying to open the connection, once it succeeds, resume the logging method (also runs on a different thread).

 

The issue is, apparently, that FSUIPCConnection.Close() isn't doing its job. The user reporting this said to me that P3D freezes for a few seconds (30-ish), and then resumes operation. I know the connection isn't being closed because i built a debug version for him and i'm getting this error:

[09:06] FSUIPCBUSY: False // Check that the thread isn't busy
[09:06] UIPCERROR: FSUIPC.FSUIPCException: FSUIPC Error #1: FSUIPC_ERR_OPEN. The connection to FSUIPC is already open.
So, i am thinking about closing the connection every time i try to open it, on my error handler method like this:
 
        private void OpenFSUIPC_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            FSUIPCConnection.Close();  // This will be added to prevent "already open" errors
            if (e.Error == null)
            {
                OpenFSUIPCTimer.Enabled = false;           // Once the error is null, disable the open connection timer
                FlightTimer.Enabled = true;                // Enable the log timer
            }
        }

My question is, is this the best way to handle the error, is there a problem of successively trying to close the connection without knowing if it is open?

 

I don't recall the .NET client having a method returning something like "is the connection already open", or i would use that instead.

 

Maybe i'm being just too much of a perfectionist (i know i am) and trying to do things in the most correct way possible, so i decided to ask here for some advice.

 

Thank you very much.

 

Nuno

 

 

 

 

Posted

Hi Nuno,

 

The connection handling in Version 2.4 isn't the best. If you attempt to connect but it fails, the DLL still thinks the connection is open. So when you try to open it again you get the error.

 

The best way around this is to always close the connection if there are any errors during the open:

try
{
    FSUIPCConnection.Open();
}
Catch (FSUIPCException ex)
{
   FSUIPCConnection.Close();
   MessageBox.Show(ex.Message);
}

Or a more ugly way is just to force a close() before open():

try
{
    FSUIPCConnection.Close();
    FSUIPCConnection.Open();
}
Catch (FSUIPCException ex)
{
   MessageBox.Show(ex.Message);
}

Calling Close() isn't a problem if the connection isn't open.

 

This problem has been fixed for the next release 3.0. If the connection fails, the connection is not left 'open'. The connection is automatically closed if the connection is lost during Process(). There is also a new property FSUIPCConnection.IsConnectionOpen so your program can ask if the connection is good or not.

 

I've attached the latest V3.0 RC1 here (built against the 4.5 framework) in case you want to try it. But, aggressive closing will work around the problems in 2.4.

 

Paul

FSUIPCClient3.0_RC1.zip

Posted

Wow, amazing. I'll get to work with this and report back.

 

Thank you very much Paul!

 

EDIT: I cannot see the attachment?

Posted
EDIT: I cannot see the attachment?

 

 

I attached the Beta instead of the RC1 version. I have to swap it. Should be there now - make sure you have the RC1 version.

 

Paul

  • Upvote 1
Posted

Thank you!

 

EDIT:

 

I am now using FSUIPCConnection.IsConnectionOpen to perform additional checks and the error detection routine is working flawlessly and implemented in a way that looks much better than previously did :)

 

Thank you again.

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.