hkhoanguyen Posted October 9, 2020 Report Posted October 9, 2020 Hello, May I ask whether FSUIPC C# has any function to monitor the change in offset/Lvars ? I'm using the timer but I would like to know if it exists like in Lua (event.offset, event.Lvars), if not do you have any idea to implement one ? Thanks
Paul Henty Posted October 9, 2020 Report Posted October 9, 2020 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
hkhoanguyen Posted October 9, 2020 Author Report Posted October 9, 2020 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
hkhoanguyen Posted February 26, 2021 Author Report Posted February 26, 2021 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
Paul Henty Posted February 26, 2021 Report Posted February 26, 2021 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
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