Andy B. Posted April 25 Report Posted April 25 I have a C# WPF app with a main window that controls startup routines. In the main window, I have the following. The user control displays connection status. Unfortunately, the connection status shows 'not connected' when the window loads if MSFS is closed. It will also display 'connected' when MSFS is loaded. When the app is running and MSFS closes, the status remains at 'connected'. It should toggle between not connected and connected based on the status of MSFS/FSUIPC. Any ideas how I can fix it? connectionTimer = new() { AutoReset = true, Enabled = true, Interval = 300, }; // Connection elapsed event. #region connectionTimer.Elapsed += (s, e) => { // Try to open the connection. Otherwise connection timer will do nothing. try { FSUIPCConnection.Open(); FSUIPCConnection.Process(); } catch(Exception ex) { } }; #endregion connectionTimer.Start(); #endregion In the user control embedded into the main window, I have the following. var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(300), IsEnabled = true, }; timer.Tick += async (s, args) => await UpdatePanelControlsAsync(); timer.Start(); private async Task UpdatePanelControlsAsync() { await Task.Run(() => { string status = FSUIPCConnection.IsOpen? "Connected" : "Not connected"; Dispatcher.Invoke(() => { connectionStatusTextBox.Text = status.ToString(); }); });
Paul Henty Posted April 25 Report Posted April 25 Hi Andy, The IsOpen property refers only to the FSUIPC connection, not the flight sim. Prior to FSUIPC7 this was effectively the same thing as FSUIPC ran inside the flight sim. WideClient.exe and FSUIPC7 run outside of the flight sim, so the connection will be open if they are running, even if the flight sim is not. If you want to know if the flight sim is open you can try polling offset 0x337E (activity counter) to make sure it's changing. See the notes in the documentation as there are times it might not update (e.g. loading new aircraft). Paul
Andy B. Posted April 25 Author Report Posted April 25 So I understand, FSUIPCConnection.IsOpen only checks to see if FSUIPC itself is actively running. It knows nothing about MSFS or its current state. When MSFS closes, my app will always return the last known state of FSUIPC, which was open at the end of the test. To deal with this, I should check the activity counter offset since it can determine if MSFS is currently loaded. I can use the offset for now, but is there a way you can add this as a property to FSUIPCConnection?
Andy B. Posted April 25 Author Report Posted April 25 I tried this offset. I have the same result as when checking IsOpen. The app shows not connected until MSFS is active, then changes to connected as expected. However, closing MSFS while the app is open still results in the connected message staying on screen, even when MSFS has completely unloaded. Restarting my app then displays not connected. Wonder why it's doing this...strange.
Paul Henty Posted April 25 Report Posted April 25 Quote . However, closing MSFS while the app is open still results in the connected message staying on scree You need to be checking the ValueChanged property of offset 0x337E. If you close MSFS and this offset is still changing (counting up), you'll need to ask John Dowson in the FSUIPC7 support forum if he has any other ideas for detecting if MSFS is unloaded. Paul
Andy B. Posted April 25 Author Report Posted April 25 Just did a test where all the timer did is report the activity count. When I started my app before MSFS was loaded, the total count is 0. After getting to the welcome screen, it still reported 0, even though IsOpen reported true. After restarting my app, I now have a total count of 219. Now, when I close MSFS, the display in my app still shows 219/connected for the current status. I don't understand, because this method works for other parts like aircraft panels. Not sure why it doesn't work here.
Paul Henty Posted April 25 Report Posted April 25 Quote After getting to the welcome screen, it still reported 0, even though IsOpen reported true. IsOpen is true because it's connected to FSUIPC7. The counter is probably doesn't update until the player has loaded an aircraft. It should start counting up when you start a flight. Quote Now, when I close MSFS, the display in my app still shows 219/connected for the current status. This seems correct then. If it's sticking at 219 then there is no activity. The ValueChanged property on 0x337E will be false. So your app knows that MSFS has been unloaded. The activity counter might also stop when the user has ended the flight and is back in the menus. Paul
Andy B. Posted April 25 Author Report Posted April 25 I figured it out. The timer that does the processing for the offsets was missing. Had to stop the connection timer when connection opens and start the process timer. If the process timer throws an exception, restart the connection timer. It all works now. 🙂 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now