Click here to Skip to main content
16,012,223 members
Home / Discussions / C#
   

C#

 
Questionin what classes do I handle/place these resources? Pin
stephen.darling13-Sep-10 19:27
stephen.darling13-Sep-10 19:27 
AnswerRe: in what classes do I handle/place these resources? Pin
SeMartens13-Sep-10 21:21
SeMartens13-Sep-10 21:21 
AnswerRe: in what classes do I handle/place these resources? Pin
OriginalGriff13-Sep-10 21:42
mveOriginalGriff13-Sep-10 21:42 
GeneralRe: in what classes do I handle/place these resources? Pin
stephen.darling13-Sep-10 21:51
stephen.darling13-Sep-10 21:51 
GeneralRe: in what classes do I handle/place these resources? Pin
SeMartens13-Sep-10 22:14
SeMartens13-Sep-10 22:14 
GeneralRe: in what classes do I handle/place these resources? Pin
OriginalGriff13-Sep-10 22:25
mveOriginalGriff13-Sep-10 22:25 
QuestionTimer events driving me insane! Pin
stephen.darling13-Sep-10 14:48
stephen.darling13-Sep-10 14:48 
AnswerRe: Timer events driving me insane! Pin
Luc Pattyn13-Sep-10 15:23
sitebuilderLuc Pattyn13-Sep-10 15:23 
Hi,

1.
you can have several timers, however I would avoid having dozens of them.

2.
you can easily combine two or more periodic timer requirements and serve them by a single timer, basically it works like this (code looks like C#, has not been tested):

public class MultiTimerDemo {
   private int timerCounter17=0;
   private int timerCounter5=0;

   public MultiTimerDemo() {
      Windows.Forms.Timer timer=new Windows.Forms.Timer();
      timer.Interval=1000;
      timer.Tick+=ticker;
      timer.Start();
   }

   private void ticker(object sender, EventArgs e) {
       // deal with first virtual timer
       if (--timerCounter5<=0) {
           timerCounter5=5;
           .. now do whatever needs to be done every 5 seconds
      }
      // deal with second virtual timer
      if (--timerCounter17<=0) {
          timerCounter17=17;
          .. now do whatever needs to be done every 17 seconds
      }
   }
}


The above illustrates how one actual timer can be turned into two or more virtual timers.
You can easily add virtual timers. And of course you could make things more dynamic (provide code to add and remove all kinds of virtual timers) by using lists and delegates.

Smile | :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.


GeneralRe: Timer events driving me insane! Pin
stephen.darling13-Sep-10 15:29
stephen.darling13-Sep-10 15:29 
AnswerRe: Timer events driving me insane! Pin
PIEBALDconsult13-Sep-10 16:45
mvePIEBALDconsult13-Sep-10 16:45 
QuestionHow do I repeat this sound file as required? Pin
stephen.darling13-Sep-10 10:12
stephen.darling13-Sep-10 10:12 
AnswerRe: How do I repeat this sound file as required? Pin
AspDotNetDev13-Sep-10 11:03
protectorAspDotNetDev13-Sep-10 11:03 
GeneralRe: How do I repeat this sound file as required? Pin
stephen.darling13-Sep-10 11:11
stephen.darling13-Sep-10 11:11 
GeneralRe: How do I repeat this sound file as required? Pin
AspDotNetDev13-Sep-10 11:42
protectorAspDotNetDev13-Sep-10 11:42 
GeneralRe: How do I repeat this sound file as required? Pin
stephen.darling13-Sep-10 12:29
stephen.darling13-Sep-10 12:29 
QuestionMessage Removed Pin
13-Sep-10 8:36
hove8213-Sep-10 8:36 
GeneralRe: ObjectPolicy Pin
OriginalGriff13-Sep-10 9:06
mveOriginalGriff13-Sep-10 9:06 
GeneralRe: ObjectPolicy Pin
Pete O'Hanlon13-Sep-10 9:07
mvePete O'Hanlon13-Sep-10 9:07 
AnswerRe: ObjectPolicy Pin
Eddy Vluggen13-Sep-10 10:43
professionalEddy Vluggen13-Sep-10 10:43 
GeneralRe: ObjectPolicy Pin
hove8213-Sep-10 10:56
hove8213-Sep-10 10:56 
GeneralRe: ObjectPolicy Pin
Eddy Vluggen13-Sep-10 11:36
professionalEddy Vluggen13-Sep-10 11:36 
GeneralRe: ObjectPolicy Pin
PIEBALDconsult13-Sep-10 14:43
mvePIEBALDconsult13-Sep-10 14:43 
GeneralRe: ObjectPolicy [modified] Pin
hove8213-Sep-10 19:54
hove8213-Sep-10 19:54 
GeneralRe: ObjectPolicy Pin
Eddy Vluggen14-Sep-10 7:52
professionalEddy Vluggen14-Sep-10 7:52 
GeneralRe: ObjectPolicy Pin
hove8214-Sep-10 8:09
hove8214-Sep-10 8:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.