Click here to Skip to main content
15,886,110 members
Home / Discussions / C#
   

C#

 
GeneralRe: TX TextControl 21.0 Document viewer example in c# Pin
PIEBALDconsult12-Sep-14 5:34
mvePIEBALDconsult12-Sep-14 5:34 
GeneralRe: TX TextControl 21.0 Document viewer example in c# Pin
Dave Kreskowiak12-Sep-14 5:39
mveDave Kreskowiak12-Sep-14 5:39 
QuestionHow to loop in timers Pin
Member 1107411510-Sep-14 21:02
Member 1107411510-Sep-14 21:02 
AnswerRe: How to loop in timers Pin
OriginalGriff10-Sep-14 21:52
mveOriginalGriff10-Sep-14 21:52 
GeneralRe: How to loop in timers Pin
Member 1107411510-Sep-14 22:02
Member 1107411510-Sep-14 22:02 
GeneralRe: How to loop in timers Pin
OriginalGriff10-Sep-14 22:09
mveOriginalGriff10-Sep-14 22:09 
GeneralRe: How to loop in timers Pin
Member 1107411510-Sep-14 22:41
Member 1107411510-Sep-14 22:41 
GeneralRe: How to loop in timers Pin
OriginalGriff10-Sep-14 22:57
mveOriginalGriff10-Sep-14 22:57 
Don't.
Do this:
C#
private enum Action
    {
    Disabled, Item1, Item2, Item3, Item4
    }
private DateTime doAfter = DateTime.MaxValue;
private Action action = Action.Disabled;

This gives you the framework you need.
Then, set up and start the timer:
C#
private void SetTimer()
    {
    Timer timer = new Timer();
    timer.Interval = 1000 * 60 * 5;  // 5 minutes
    timer.Tick += new EventHandler(timer_Tick);
    timer.Start();
    action = Action.Item1;
    doAfter = DateTime.Now.Date.AddDays(1);  // Midnight tomorrow.
    }
And then handle the Tick:
C#
private void timer_Tick(object sender, EventArgs e)
    {
    if (DateTime.Now >= doAfter)
        {
        switch (action)
            {
            case Action.Item1:
                action = Action.Item2;
                doAfter = doAfter.AddMinutes(15);
                // Do item 1
                break;
            ...
            case Action.Item4:
                action = Action.Item1;
                doAfter = DateTime.Now.Date.AddDays(1);
                // Do item 4
                break;
            }
        }
    }

And it handles it all for you.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

GeneralRe: How to loop in timers Pin
Member 1107411524-Sep-14 19:56
Member 1107411524-Sep-14 19:56 
QuestionThreading issue Pin
SledgeHammer0110-Sep-14 10:23
SledgeHammer0110-Sep-14 10:23 
AnswerRe: Threading issue Pin
PIEBALDconsult10-Sep-14 11:29
mvePIEBALDconsult10-Sep-14 11:29 
GeneralRe: Threading issue Pin
SledgeHammer0110-Sep-14 12:14
SledgeHammer0110-Sep-14 12:14 
GeneralRe: Threading issue Pin
PIEBALDconsult10-Sep-14 15:18
mvePIEBALDconsult10-Sep-14 15:18 
Questionwebrowser control Pin
Member 1105956910-Sep-14 8:26
Member 1105956910-Sep-14 8:26 
AnswerRe: webrowser control Pin
Eddy Vluggen10-Sep-14 8:29
professionalEddy Vluggen10-Sep-14 8:29 
Generalwebrowser control Pin
Member 1105956910-Sep-14 8:42
Member 1105956910-Sep-14 8:42 
GeneralRe: webrowser control Pin
Eddy Vluggen10-Sep-14 9:57
professionalEddy Vluggen10-Sep-14 9:57 
GeneralRe: webrowser control Pin
Member 1105956912-Sep-14 9:50
Member 1105956912-Sep-14 9:50 
GeneralRe: webrowser control Pin
Eddy Vluggen12-Sep-14 11:00
professionalEddy Vluggen12-Sep-14 11:00 
GeneralRe: webrowser control Pin
Member 1105956913-Sep-14 23:36
Member 1105956913-Sep-14 23:36 
Questionadd code to build millisecond to testing progressbar in c# 2008 Pin
KaKoten9-Sep-14 18:40
KaKoten9-Sep-14 18:40 
AnswerRe: add code to build millisecond to testing progressbar in c# 2008 Pin
PIEBALDconsult9-Sep-14 19:45
mvePIEBALDconsult9-Sep-14 19:45 
GeneralRe: add code to build millisecond to testing progressbar in c# 2008 Pin
KaKoten11-Sep-14 1:39
KaKoten11-Sep-14 1:39 
AnswerRe: add code to build millisecond to testing progressbar in c# 2008 Pin
CPallini9-Sep-14 19:59
mveCPallini9-Sep-14 19:59 
GeneralRe: add code to build millisecond to testing progressbar in c# 2008 Pin
KaKoten11-Sep-14 1:39
KaKoten11-Sep-14 1:39 

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.