How to wait for a specific period without suspending the app

Login to reply to this topic.
Mon, 2005-12-05 08:34
Joined: 2005-07-10
Forum posts: 68
Hello,

Is there any way to wait for a period of time with out suspending the application? I know I could do it with some timer class and by implementing some interface. But my waiting task is very trivial and donÂ’t want to add that much overhead of class or interface in my code. So I am just curious to know is there any possibilities to make my app wait for few seconds ( 1 or 2 sec ) without suspending?

Mon, 2005-12-05 08:55
Joined: 2005-08-11
Forum posts: 278
Re: How to wait for a specific period without suspending the app
i'm not sure i clearly understand you question..but if you want your application to wait for 1 or two seconds use User::After function... Smiley
Mon, 2005-12-05 08:58
Joined: 2005-07-10
Forum posts: 68
Re: How to wait for a specific period without suspending the app
well, User::After() suspends the current thread until a specified time interval has expired. But I dont want my app to be suspended. I am looking for some non-suspending way to wait for some period of time.

Mon, 2005-12-05 09:20
NewLC AdministratorSymbian AccreditedForum Nokia Champion
Joined: 2003-01-14
Forum posts: 2006
Re: How to wait for a specific period without suspending the app
You can use a timer for that purpose. Take a look at the CTimeOutTimer class you can found in various examples within Nokia SDK (at least those ones: networking, animation, sockets and irda)

Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant

Mon, 2005-12-05 09:31
Joined: 2005-07-10
Forum posts: 68
Re: How to wait for a specific period without suspending the app
So it seems there is no way to do it simply by calling some static methods. Well, I knew I could do it by using some timer class. As i said my waiting task is very minor, so I wonder that there might be some easy way to do it. Thanks anyway! 
Mon, 2005-12-05 09:54
Joined: 2003-10-15
Forum posts: 78
Re: How to wait for a specific period without suspending the app
Actually there is an "almost" seamless way of doing it.
Have a look at CActiveSchedulerWait class.
To "insert" a pausing into the existing code, you'll have to create the CActiveSchedulerWait somewhere (e.g. in a constructor) and call its Start() when you need to make a pause.

Still, you'll have to use some timer object, but from its callback you can just call iYourSchedulerWait->AsyncStop() and the paused function will be resumed.

I believe it is one of the simplest ways of adding an "async pause" into the existing program

Mon, 2005-12-05 11:29
Joined: 2005-08-11
Forum posts: 278
Re: How to wait for a specific period without suspending the app
you can use acitve objects.. using this your application won't get suspended ...while waiting for something you can do other things ... Also you can wait for some key pressed event  for your application to start(async)..[Just a suggestion Grin]
Mon, 2005-12-05 14:42
Joined: 2005-07-10
Forum posts: 68
Re: How to wait for a specific period without suspending the app
Finally I used CTimeOutTimer class suggested by eric. I wanted to try the way as doctor suggesed. But after reading the API doc, I am discouraged to do so (from API doc:- "Note, however, that the use of nested scheduler loops is strongly discouraged"). Thanks all of you guys.

Br,
madsum
Mon, 2005-12-05 15:03
Joined: 2003-10-15
Forum posts: 78
Re: How to wait for a specific period without suspending the app
If it works, than congratulations! Smiley

In fact I meant using some timer together with CActiveSchedulerWait Smiley
There is nothing too bad in using nested loops. You should be careful only about calling one AsyncStop() for every Start().

Using only timer is generally better, at least because it is simpler. You would need to add CActiveSchedulerWait if at some point you realize that you need split an existing long function into several steps executed in several ActiveScheduler time slots. If you'll ever have to do it, introducing CActiveSchedulerWait is usually simpler and more reliable than re-engineer logic and actually splitting a long function into several

  • Login to reply to this topic.