what is the role of timer here
here the code what is the actual role of timer,,other thing is which if(s开发者_StackOverflowaving) will trigger first ,if modification not happened means server fail..Is there any relation with thread..
private void Dlg_Load(object sender, System.EventArgs e)
{
// Set the message.
if (Saving)
eLabel.Text = Managers.ControlStrings.GetString("Saving");
// Setup to receive events.
Server.InfoReceived += new InfoEventHandler(Server_InfoReceived);
Server.Received += new ServerStateEventHandler(Server_ServerStateReceived);
// Start the timer to begin saving as soon as the dialog has completed setup.
Timer.Start();
}
/// Handle the tick of the timer by stopping the timer and beginning the operation. This allows
/// the dialog to come up fully before the operation is started; otherwise there are problems
/// closing the dialog.
/// </summary>
/// <param name="sender">Timer.</param>
/// <param name="e">Ignored.</param>
private void Timer_Tick(object sender, System.EventArgs e)
{
string func = "Dlg.Timer_Tick";
try
{
// Stop timer
Timer.Stop();
if (Saving)
if (!Server.Modify())
{
}
}
}
The only clue we have here is the XML comment:
/// Handle the tick of the timer by stopping the timer and beginning the operation.
/// This allows the dialog to come up fully before the operation is started;
/// otherwise there are problems closing the dialog.
Apparently there is a problem with the sequence of initialization. It smells a bit like a hack, but we don't see enough code to decide what exactly.
Read the comments in the code.
It is to wait for everything to be drawn correctly before doing the action in the timer event.
Application.DoEvents()
is sometimes used for similar "waiting".
I guess that the timer interval is 1 millisecond.
it's look like it is a bad way to wait for a dialog to be display in order (saving?) to do something when the dialog is displayed.
精彩评论