How to tell if sim is already running

Hi,

I've created a standalone MFC application. Simconnect is working well. I subscribed to "simstart" and "simstop". "simstart" fires when the environment is loaded each time. Problem is, sometimes the sim is already running when my app starts. Is there a way I can know that the sim is already running so that my app knows to to go ahead and Init and begin processing?

Tx,
Gregg
 

ddawson

Resource contributor
Request data on one of the time variables. If the value is changing, the sim is running.
Also, I think when you subscribe to events like 'simstart' you will get an immediate return with the current value.
 
Request data on one of the time variables. If the value is changing, the sim is running.
Also, I think when you subscribe to events like 'simstart' you will get an immediate return with the current value.
Thanks Doug. I did subscribe to simstart and I do get a message when I click a menu item and then close the resultant dialog. If the sim was already running, however, the simstart message didn't happen when I started my app . I'll look at the time option.

SimConnect_RequestSystemState
Thanks. I'll take a look.
 
SimConnect_RequestSystemState
I've been mulling this idea. After I call SimConnect_Open, I could call both of these together:
hr = SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_SIM_START, "SimStart");
hr = SimConnect_RequestSystemState(hSimConnect, EVENT_SIM_STATE, "Sim");

If the sim is already running then I'd get an immediate 0 in SIMCONNECT_RECV_ID_SYSTEM_STATE "EVENT_SIM_STATE and know to go ahead and initialize. If I got 1 (or any other value) from SIMCONNECT_RECV_ID_SYSTEM_STATE EVENT_SIM_STATE then I'd just not initialize and wait for the SIMCONNECT_RECV_ID_EVENT EVENT_SIM_START event and start my initialization then. Is that the best way?

Gregg
 

ollyau

Resource contributor
The documentation says that Sim returns 1 if the user has control and 0 if the user is in the UI:

Requests the state of the simulation. If 1 is returned, the user is in control of the aircraft, if 0 is returned, the user is navigating the UI. This is the same state that notifications can be subscribed to with the "SimStart" and "SimStop" string with the SimConnect_SubscribeToSystemEvent function.
On the subject of SimStart, the SDK documentation has this to say:

The simulator is running. Typically the user is actively controlling the aircraft on the ground or in the air. However, in some cases additional pairs of SimStart/SimStop events are sent. For example, when a flight is reset the events that are sent are SimStop, SimStart, SimStop, SimStart. Also when a flight is started with the SHOW_OPENING_SCREEN value (defined in the FSX.CFG file) set to zero, then an additional SimStart/SimStop pair are sent before a second SimStart event is sent when the scenery is fully loaded. The opening screen provides the options to change aircraft, departure airport, and so on.
 
Hi,

I've created a standalone MFC application. Simconnect is working well. I subscribed to "simstart" and "simstop". "simstart" fires when the environment is loaded each time. Problem is, sometimes the sim is already running when my app starts. Is there a way I can know that the sim is already running so that my app knows to to go ahead and Init and begin processing?

Tx,
Gregg
To determine if FSX is "Running", check to see if the process "fsx" exists.

ie

if (System.Diagnostics.Process.GetProcessesByName("fsx").Length == 0)
{
// FSX is NOT running
return;
}


Note: The OP is asking if FSX is running or not -- NOT asking if Simconnect is working
Geoff
 
Here is how I do it in C#

System.Diagnostics.Process[] ieProcs = Process.GetProcessesByName("fsx");
if (ieProcs.Length > 0)
{
foreach (System.Diagnostics.Process p in ieProcs)
{
hWnd = p.MainWindowHandle;
// fsx is running - do stuff here
}
}
 
I understand that GetProcessesByName() is only for .NET and not for C++?
I think you will find that you can use still do this in C++

ie

[C++]
#using <mscorlib.dll>
#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::ComponentModel;

int main() {
// Get the current process.
Process* currentProcess = Process::GetCurrentProcess();

// Get all instances of Notepad running on the local
// computer.
Process* localByName[] = Process::GetProcessesByName(S"FSX");

// Get all instances of FSX running on the specific
// computer.
// 1. Using the computer alias (do not precede with "\\").
Process* remoteByName[] = Process::GetProcessesByName(S"FSX", S"myComputer");

// 2. Using an IP address to specify the machineName parameter.
Process* ipByName[] = Process::GetProcessesByName(S"FSX", S"169.0.0.0");

// Get all processes running on the local computer.
Process* localAll[] = Process::GetProcesses();

// Get all processes running on the remote computer.
Process* remoteAll[] = Process::GetProcesses(S"myComputer");

// Get a process on the local computer, using the process id.
Process* localById = Process::GetProcessById(1234);

// Get a process on a remote computer, using the process id.
Process* remoteById = Process::GetProcessById(2345, S"myComputer");
}


Ref:
https://msdn.microsoft.com/en-us/library/aa326947%28v=vs.71%29.aspx


Geoff

Note :D = : D (without space) -- cannot find option here to stop this happening !!
 
Last edited:

n4gix

Resource contributor
Note :D = : D (without space) -- cannot find option here to stop this happening !!
Geoff, it is simple enough. Click on the "Insert" icon (just to the left of the 3 1/4" disk icon), then paste your code in the popup box.
Code:
using namespace System::Diagnostics;
Alternatively, you can simply type {code}insert code here{/code} (using square brackets [ ]instead of braces { })
 
Geoff, it is simple enough. Click on the "Insert" icon (just to the left of the 3 1/4" disk icon), then paste your code in the popup box.
Code:
using namespace System::Diagnostics;
Alternatively, you can simply type {code}insert code here{/code} (using square brackets [ ]instead of braces { })
Thanks Bill (yet again)

I have lost count of the number of times you have helped me ... each time is greatly appreciated.

Geoff
 
I think you will find that you can use still do this in C++
Have you tried using this and on which type of Visual C++ 2010 Express project:

CLR Console Application
CLR Empty Project
Empy Project
Win32 Console Application
Win32 Project
Windows forms Application


(I assume Class Library and Makefile Projects aren't relevant?)

I'm having problems :(
 
Have you tried using this and on which type of Visual C++ 2010 Express project:

CLR Console Application
CLR Empty Project
Empy Project
Win32 Console Application
Win32 Project
Windows forms Application


(I assume Class Library and Makefile Projects aren't relevant?)

I'm having problems :(
No, I have not tried this in C++ ... only in C#

Which is why I referenced the original MSDN information source.

https://msdn.microsoft.com/en-us/library/aa326947%28v=vs.71%29.aspx
 
Top