Advertisement Jump to content
Sign in to follow this  
tranduy

CALLBACK TimerProc

This topic is 4901 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, I have a class like this: class CNet { public: //... int WaitTime; bool IsLoginSuccess; void Login(CString servAddr,CString servPort); //... } void CNet::Login(....) { bool bConnectSuccess = mSocket.Connect(...); if (bConnectSuccess) { // send username and password to server - it's done because I can see // these data in server SendData(userNpassword); // the client will be set at waiting mode. After 10s, if there's no answer // from server: auto-disconnect WaitTime = 0; // ---------- AND MY PROBLEM IS FROM HERE ------ // I want to use a timer (interval is 1000ms) to increase the WaitTime // but don't know how to use } } void CNet::????(1000) // it is will be timer event, is it? { WaitTime ++; if (WaitTime >= 10) ( IsLoginSuccess = false; mSock.DisConnect(); ) else IsLoginSuccess = true; } Pls help me to solve that function. Thank you very much. Regards,

Share this post


Link to post
Share on other sites
Advertisement
What operating system are you using? It's probably better to use a timer proc provided by the operating system than crafting one of your own.

Share this post


Link to post
Share on other sites
u could try using Sleep in ur home-grown 'timer' loop, but Sleep suspends ur active thread. In a GUI application, that would mean even your GUI will not update until the Sleep duration is over. Multi-threading is needed for this to work elegantly.

Another option is to use SetTimer (i think thats wat its called). Check out MSDN for a reference on setting up system level timers that work via callbacks. It might be a more elegant and compatible way to get around this issue.

Share this post


Link to post
Share on other sites
There's select as a form of sleep

OR! in your WinProc catch WM_TIMER set the CallBackProc to NULL and set a vaild identifier. Check MSDN for your WM_TIMER paramters.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!