Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Mystery Bug with Timer

Featured Replies

I have a mystery problem with a Windows timer.I used to have a code like this:

timerId = SetTimer(GetFSWindow(), 0, 200, (TIMERPROC)TimerTick);

where GetFSWindow() returns the window handle of the FS window "FS98MAIN".This code used to work fine, and I changed other parts of the code. Then it appeared that the timer didn't work any more, the TImerTick function was not called any more. I tried to understand why, but I couldn't...So I changed the code into this:

timerId = SetTimer(0, 0, 200, (TIMERPROC)TimerTick);

The code now works fine again, my TimerTick function is called every 200 milliseconds. But I still wonder why a code that was working stopped working, and why changing the window handle by 0 could make it work again.If someone can help me understanding...Thanks,Eric

  • Moderator

Possibly because the parameter list has been expanded from 3 to 4?

UINT_PTR SetTimer(	HWND hWnd,	UINT_PTR nIDEvent,	UINT uElapse,	TIMERPROC lpTimerFunc);

Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator
  • Commercial Member

Description of the first parameter:"Handle to the window to be associated with the timer. This window must be owned by the calling thread. If a NULL value for hWnd is passed in along with an nIDEvent of an existing timer, that timer will be replaced in the same way that an existing non-NULL hWnd timer will be."Since you don't actually 'own' the FS window... you probably shouldn't be passing that window handle to the SetTimer function. Your timer needs to run 'independently', thus a NULL (0) value is best.When you define a 'SetTimer', a window can get a WM_TIMER message telling it to handle the timer. This could be one of the reasons why it's no longer working for you.

Ed Wilson

Mindstar Aviation
My Playland - I69

  • Author
Description of the first parameter:"Handle to the window to be associated with the timer. This window must be owned by the calling thread. If a NULL value for hWnd is passed in along with an nIDEvent of an existing timer, that timer will be replaced in the same way that an existing non-NULL hWnd timer will be."Since you don't actually 'own' the FS window... you probably shouldn't be passing that window handle to the SetTimer function. Your timer needs to run 'independently', thus a NULL (0) value is best.When you define a 'SetTimer', a window can get a WM_TIMER message telling it to handle the timer. This could be one of the reasons why it's no longer working for you.
Yes, I think you're right. Maybe FS defines another timer with the same id as mine, so FS in fact replaces my timer.I still don't know why it was working before...I don't use the WM_TIMER message because I don't have a window (it is in a gauge), I just do what needs to be done in the timer proc that is called by the timer. At this time, everything seems to work fine.Thanks for your help !!Eric

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.