0

I am creating an application in that I need to use about 20 different Timers.

But all the timers are going to be created at run time, by calling some function.

All the timers might having different timer interval and all timer do have different counters that will be reduced by one with passing of 1 minute.

Now when the counter will become 0 the timer will be stopped. But in my application all timers have different counter values and I want to stop different timers at it's time interval using a single function.

I know that we can create different timers and by providing the selector values to their respective timer functions , we can stop the timer by I don't have idea that how many timers are running at a time , and if I do stop a single timer at a time then it will lead to stop all the timers and the functionality is not showing properly.

Please help me by providing any logic or samples How to stop multiple timers using single function at different time interval.

thanks in advance

V.V
  • 3,082
  • 7
  • 49
  • 83

1 Answers1

0

I think you may want to reconsider your software design. You can call your method as normal:

[self method];

And then at the end of each method, do the following:

[self performSelector:@selector(method) withObject:nil afterDelay:(1000)];

This will create a loop. You can then increment an integer and do something else when that counter reaches 0. You'll be able to manage your code much more effectively. You may still need timers for some situations, but this will definitely be more efficient than the 20 timers you were planning on using.

Aurum Aquila
  • 9,126
  • 4
  • 25
  • 24
  • This is the efficient way you are correct but after each minute I need to decrement the counter value and if in between if any one changes the value then the counter value will be increased by adding the remaining time. SO at that time this will not be a proper way as I am not able to increase or Decrease the counter at each minute. – V.V Jan 21 '11 at 06:00