Click here to Skip to main content
16,019,876 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a timer applicaion as shown below

static void Main(string[] args)
        {
           Timer timer1 = new Timer();
            timer1.Elapsed += new ElapsedEventHandler(timer1_Elapsed);
            timer1.Interval = 6000;
            //timer1.Enabled = true;
            timer1.Start();
            while (true) ;            
            
        }


static void timer1_Elapsed(object sender, ElapsedEventArgs e)
        {   
            Console.WriteLine("--------------------------------------------------------->");
            Check_newLab();
            Console.WriteLine("Done ");
            create_new_folder();
            Console.WriteLine("Begining to download ");
            Download_file();
            Console.WriteLine("Prepearing files ");
            Writetodatabase();
            Console.WriteLine("--------------------------------------------------------->");
            
        }


I am not able type timer1.stop(); inside the void timer1_Elapsed.

What i want is when the timer is triggered and reached the void timer1_Elapsed i wan to disable the timer so half way through running the sub function it is not retriggered. which mean when inside void timer1_Elapsed the timer should not be triggerred.
Posted

If you want that the Elapsed event should be fired only the first time the interval is passed, set Enabled to true and AutoReset to false for the timer.

Update: Set AutoReset for the timer to false and explicitly start it again in the elapsed event. Your Elapsed event should have something like this:

(sender as Timer).Start();

preferably in the finally block or at the end of try.
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 5-Apr-11 4:04am    
Good, my 5.
--SA
Amd_eagle 5-Apr-11 4:28am    
No i want the timer to be fired every time. the timer should not fire when it is doing completing the jobs inside the routines.Once it complete the routine then it can start firing timer again
dan!sh 5-Apr-11 4:57am    
Updated the reply.
timer has got the property enabled...
you can use the property either to true or false..
accourding to the program need...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900