Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Pls any one tel me hw to use timer in windows application means some events happens at particular time...like backup scheduling pls pls advance thkx...
Posted 1-Oct-12 10:50am
vinrsg428
Comments
Sergey Alexandrovich Kryukov at 1-Oct-12 17:34pm
   
There are at least four different timer classes... They are fine except the one you probably keep in mind, System.Windows.Forms.Timer. It's simplest to use but expect no accuracy at all. In many cases, using an extra thread is way more straightforward and less error-prone. It really depends on the purpose. Would you just read the MSDN help and try to solve the problem, ask a question if you face a problem, how about that. Otherwise -- "how to use" is a bit unclear. What, all steps? Too much, IMHO, especially when one of the four is not yet selected...
--SA
Sergey Alexandrovich Kryukov at 1-Oct-12 17:41pm
   
More likely, for backup you would need the Windows Scheduler instead. OK, please see my answer.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

To start with, just for your reference:
 
http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx[^],
http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.aspx[^] (this one is less known; and it can be used with Forms as well, not only with WPF, as well as Dispatcher).
 
Those are four different timer classes you could use. First read the MSDN help to see what's better for you. Still, consider working with additional thread.
 
And finally, let's remember that you are talking about the backup. This could make all the timers not quite suitable, as well as the "scheduling thread". You might need a better approach, a special one.
 
Usually, backup is done according to some schedule. And you don't need to write your own Windows Service. The Service you need already exists, called Windows Task Scheduler, see:
http://en.wikipedia.org/wiki/Task_Scheduler[^],
http://msdn.microsoft.com/en-us/library/aa383614.aspx[^],
http://msdn.microsoft.com/en-us/library/aa384006%28v=VS.85%29.aspx[^].
 
See the last link above for use of the Windows Task Scheduler. You can use its API in your program using Task Scheduler Managed Wrapper, see http://taskscheduler.codeplex.com/[^].

But if can be even simpler.
You can use Windows Task Scheduler using Windows utilities AT.EXE or SchTasks.EXE, see:
http://en.wikipedia.org/wiki/At_(Windows)[^],
http://technet.microsoft.com/en-us/library/bb490866.aspx[^],
http://en.wikipedia.org/wiki/Schtasks[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/bb736357%28v=vs.85%29.aspx[^].
 
—SA
  Permalink  
Comments
Espen Harlinn at 1-Oct-12 17:43pm
   
Good reply :-D
Sergey Alexandrovich Kryukov at 1-Oct-12 18:10pm
   
Thank you, Espen.
--SA
vinrsg at 2-Oct-12 2:58am
   
thkx a lot...
Sergey Alexandrovich Kryukov at 2-Oct-12 10:29am
   
You are welcome.
Please consider accepting the answer formally (green button) -- thanks.
--SA
ridoy at 2-Oct-12 2:03am
   
lots of info..+5
Sergey Alexandrovich Kryukov at 2-Oct-12 10:30am
   
Thank you,
--SA
Abhinav S at 2-Oct-12 2:16am
   
5! I just could not find any links you haven't posted.
:)
Sergey Alexandrovich Kryukov at 2-Oct-12 10:30am
   
No, you could... the links are not a main thing.
Thank you, Abhinav.
--SA

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

  Print Answers RSS
0 Nirav Prabtani 298
1 OriginalGriff 289
2 Sergey Alexandrovich Kryukov 225
3 _Amy 165
4 Richard MacCutchan 135
0 OriginalGriff 7,799
1 Sergey Alexandrovich Kryukov 6,966
2 Maciej Los 3,994
3 Peter Leow 3,708
4 CHill60 2,742


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 2 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100