I am curious about this, too. In fact, polling is an „accepted“ way of querying sim vars, as it seems. As you say, all tutorial examples I have found so far - including actual applications on e.g. github.com - use either a timer or a „polling loop“ (even as mercilessly to the CPU as „while (true) loop… sleep(1) end loop“)
Interestingly though:
http://www.prepar3d.com/SDKv4/sdk/simconnect_api/references/general_functions.html#SimConnect_CallDispatch
„ It is important to call this function sufficiently frequently that the queue of information received from the server is processed (typically it is coded within a while loop that terminates when the application is exited)“
So this seems to confirm that polling is the way to go. But…
„ However, if the project involves developing a library (DLL) rather than an application (EXE) then only one call to this function is necessary. This call will store the name of the callback in a cache, and whenever a packet is sent to the client, the callback function will be run“.
An example DLL setup with int __stdcall DLLStart(void) and void __stdcall DLLStop(void) is given.
So from what I understand from this, if you implement your SimConnect logic in a DLL:
- You connect to the flight simulator when the DLL is loaded (started), and…
- … call SimConnect_CallDispatch in that same „start“ function, but only once.
- Due to some black magic the actual SimConnect.dll logic then „remembers“ (caches) your callback and - according to the documentation - calls it whenever messages (sim vars, possibly also sim events…) arrive
Now why one cannot register the callback by other means such that it is called whenever messages arrive (except this DLL voodoo magic) is beyond me. And quite possibly this may be specific to the Prepar3D implementation!
And there is an obvious disadvantage, too: the flight simulator already needs to be up and running in order to be able to connect when the DLL is loaded.
(Not sure whether the same mechanism works when dynamically loading/unloading the DLL (as a „plugin“), which would allow to „reconnect“ dynamically at runtime of the client application).
I haven‘t tried this DLL approach just yet (I am only like three days into my own experiments ;)), but would be interested in any findings, too. Especially whether there is not another way to register the callback, such that we can avoid calling „dispatch“ in a polling way.