代码C#.Net后启用按钮

时间:2015-12-29 23:14:19

标签: c# .net

我在点击按钮时尝试禁用按钮,按钮代码完成后,应启用按钮。 请注意,我只使用Thread.Sleep(500)一次。我知道如何禁用按钮,但我无法正常启用按钮。它在文本出现在textBox之前启用。

private void CPU_Click(object sender, EventArgs e)
    {
        //Disable button after click
        CPU.Enabled = false;

        //Put cursor in the end of MonitorLog 
        endPointer();

        MonitorLog.AppendText("********************************************\r\n");
        MonitorLog.AppendText("Starting System Monitor\r\n\n");

        //Check for CPU usage 
        var perfCpuCount = new PerformanceCounter
            ("Processor Information", 
            "% Processor Time", 
            "_Total");

        //Hide printing first CPU usage value which is always 0%
        perfCpuCount.NextValue();
        Thread.Sleep(500);
        //Changing CPU usage value to number with 2 decimal places and printing it out
        double cpuUsage = Math.Round(perfCpuCount.NextValue(), 2);

        MonitorLog.SelectionFont = new Font(MonitorLog.Font, FontStyle.Bold);
        MonitorLog.AppendText("CPU Usage:");
        MonitorLog.SelectionFont = new Font(MonitorLog.Font, FontStyle.Regular);
        MonitorLog.AppendText(string.Format(" {0}%\r\n\n", cpuUsage));

        //Scrolling to the end of the richTextBox
        scrollToEnd();

        CPU.Enabled = true;


    }

0 个答案:

没有答案