C# 计时器在这里的作用是什么

C# 计时器在这里的作用是什么,c#,timer,C#,Timer,这里的代码是什么是定时器的实际角色,另一件事是如果(保存)将首先触发,如果修改没有发生意味着服务器失败..是否与线程有任何关系 private void Dlg_Load(object sender, System.EventArgs e) { // Set the message. if (Saving) eLabel.Text = Managers.ControlStrings.GetString("Saving"); // Setup to re

这里的代码是什么是定时器的实际角色,另一件事是如果(保存)将首先触发,如果修改没有发生意味着服务器失败..是否与线程有任何关系

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())
            {

            }
    }
}
private void Dlg\u加载(对象发送方,System.EventArgs e)
{
//设置消息。
如果(保存)
eLabel.Text=Managers.ControlStrings.GetString(“保存”);
//设置为接收事件。
Server.InfoReceived+=新的InfoEventHandler(Server\u InfoReceived);
Server.Received+=新的ServerStateEventHandler(Server\u ServerStateReceived);
//一旦对话框完成设置,启动计时器开始保存。
Timer.Start();
}
///通过停止计时器并开始操作来处理计时器的滴答声。这允许
///在操作开始前完全弹出的对话框;否则就有问题了
///关闭对话框。
/// 
///计时器。
///忽略。
私有无效计时器(对象发送方,System.EventArgs e)
{
字符串func=“Dlg.Timer_Tick”;
尝试
{
//停止计时器
Timer.Stop();
如果(保存)
如果(!Server.Modify())
{
}
}
}

当对话框显示时,等待对话框显示以便(保存?)执行某些操作,这似乎是一种不好的方式。

阅读代码中的注释

在计时器事件中执行操作之前,等待所有内容正确绘制。
Application.DoEvents()
有时用于类似的“等待”


我猜计时器间隔是1毫秒。

这里唯一的线索是XML注释:

/// 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.

显然,初始化顺序有问题。它闻起来有点像黑客,但我们没有看到足够的代码来决定到底是什么。

这并不意味着你是个蠢货,但你能回到你的问题并修改以使用完整的句子吗?嗯,这是一种黑客模式,在表单完全加载之前取消执行。