Jump to content
The simFlight Network Forums

Monitor changes in offset/Lvars


Recommended Posts

Hi,

There is no event system in the DLL like event.offset. FSUIPC cannot notify a connected application, it can only respond to requests. 

For offsets you can know if they have changed since the last Process() by checking the ValueChanged property.

For LVars this doesn't exist, so you have to compare the new value with the old.

If you want to create an real C# event system you would need to set up a timer to keep reading the offsets and then fire an event when you detect changes.

Paul

Link to comment
Share on other sites

On 10/9/2020 at 8:28 PM, Paul Henty said:

Hi,

There is no event system in the DLL like event.offset. FSUIPC cannot notify a connected application, it can only respond to requests. 

For offsets you can know if they have changed since the last Process() by checking the ValueChanged property.

For LVars this doesn't exist, so you have to compare the new value with the old.

If you want to create an real C# event system you would need to set up a timer to keep reading the offsets and then fire an event when you detect changes.

Paul

Hello Paul, thanks for your reply,

Ok, so i will continue using my timer, one question, in the timer, I'm implementing GSX auto selection, and between each GSX selection, I use Thread.sleep(500) : 

--my timer interval 500 msecs

FSUIPCConnection.SendKeyToFS(Keys.F12, SendModifierKeys.Control, null);
Thread.Sleep(500);
FSUIPCConnection.SendKeyToFS(Keys.F1, SendModifierKeys.None, null);
Thread.Sleep(500);
FSUIPCConnection.SendKeyToFS(Keys.F1, SendModifierKeys.None, null);
Thread.Sleep(500);

--my timer interval 500 msecs

Do you think it (Thread.sleep) is  a good and efficient way to do ? 

Could you suggest me any other way to have a slight delay between keypresses ? @Paul Henty

Link to comment
Share on other sites

  • 4 months later...
On 10/9/2020 at 9:46 PM, hkhoanguyen said:

Hello Paul, thanks for your reply,

Ok, so i will continue using my timer, one question, in the timer, I'm implementing GSX auto selection, and between each GSX selection, I use Thread.sleep(500) : 


--my timer interval 500 msecs

FSUIPCConnection.SendKeyToFS(Keys.F12, SendModifierKeys.Control, null);
Thread.Sleep(500);
FSUIPCConnection.SendKeyToFS(Keys.F1, SendModifierKeys.None, null);
Thread.Sleep(500);
FSUIPCConnection.SendKeyToFS(Keys.F1, SendModifierKeys.None, null);
Thread.Sleep(500);

--my timer interval 500 msecs

Do you think it (Thread.sleep) is  a good and efficient way to do ? 

Could you suggest me any other way to have a slight delay between keypresses ? @Paul Henty

HEllo @Paul Henty

Could you help me to find the answer for the question above ? thanks

Link to comment
Share on other sites

Hi,

Sorry I missed your questions.

If you find you need delays between the keypresses then Thread.Sleep is the only way I can think of.

If you're running this on the main User Interface thread (e.g. inside your main form) then it will cause your application to stop responding while it's sleeping.

If that's a problem you can run the keypress code on a background thread. Your code will still pause, but the User Interface will not lock up. 

The easiest way to do this is to use Tasks:

1. Put your key press code in its own method:

        private void SelectGSXMenu()
        {
            FSUIPCConnection.SendKeyToFS(Keys.F12, SendModifierKeys.Control, null);
            Thread.Sleep(500);
            FSUIPCConnection.SendKeyToFS(Keys.F1, SendModifierKeys.None, null);
            Thread.Sleep(500);
            FSUIPCConnection.SendKeyToFS(Keys.F1, SendModifierKeys.None, null);
            Thread.Sleep(500);
        }

2. Mark your Timer method with the async keyword: e.g.:

 private async void timer1_Tick(object sender, EventArgs e)

3. When you need to make the menu selection inside the timer use this syntax to call the new method on a background thread:

await Task.Run(() => SelectGSXMenu());

It will still take 1.5 seconds to do the keypresses, but your application will not lock up.

If your program logic doesn't need to wait for the menu selection to complete, you can remove the async and await keywords. The menu selection will then be done in the background while your main timer continues.  

Paul

Link to comment
Share on other sites

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.