i have go through the msdn library about this timer class change function ,
http://msdn.microsoft.com/en-us/library/yz1c7148.aspx
public bool Change( int dueTime, int period )
But i do not understand what is the period parameter for.
i also try to create a sample to see what it for but seems like it is doing nothing
Timer JobTime = new Timer(timer =>
{
try
{
WriteLog(DateTime.Now.ToString(), "TestJobTimer"); //Save invoke time to file
((Timer)timer).Change(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(20));
}
catch(Exception ex)
{
string stop = ex.Message;
}
});
JobTime.Change(0, 0);
Base on this sample , what i get is the timer will repeat every 5 second , thus what is the PERIOD paramenter for ?
Thank you
C is a structured, procedural programming language that has been widely used both for operating systems and applications and that has had a wide following in the academic community. Many versions of UNIX-based operating systems are written in C.
C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.
C is an imperative procedural language supporting structured programming, lexical variable scope, and recursion, with a static type system. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support.
C is very fast in terms of execution time. Programs written and compiled in C execute much faster than compared to any other programming language. C programming language is very fast in terms of execution as it does not have any additional processing overheads such as garbage collection or preventing memory leaks etc.
dueTime shows when the first event will be fired,
period how often after that
in your case the first event will be fired after 5 second then after every 20 seconds
EDIT
As far as you are calling your timer change with 0,0, it starts impatiently and on timer tick call you change it to fire after 5 seconds every 20 second, that's why event fires every 5 seconds
If you want to fire event every 20 seconds after 5 seconds, remove timer change from handler, and start timer only once like this
Timer JobTime = new Timer(timer =>
{
try
{
Console.WriteLine(DateTime.Now.ToString(), "TestJobTimer"); //Save invoke time to file
}
catch (Exception ex)
{
string stop = ex.Message;
}
});
JobTime.Change(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(20));
Hope this helps
DueTime = time until first deployment
Period = amount of time after due time for next deployment, and amount of time for each subsequent deployment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With