51069193
In real-world development, if you need to display background processing in real time, we may want to use some controls in the foreground to display
So we may write things like Label1.text=...,button1.hide (), wait for such code, but we will find that it does not immediately show, as a rookie, I do not know what is going on, but I found a solution
Application.doevents ()
This command can immediately refresh the foreground, so can be added in the appropriate location in the program code, can simulate the feeling of synchronization, but because this process is time-consuming, so it will have some impact on computational performance, or use it cautiously
https://bbs.csdn.net/topics/380001753
Application.doevents ();
This is the continuation of the main thread operation
/// <param name="i">时间 单位:秒</param>
private
void
dealTimer(
int
i)
{
DateTime dt1 = DateTime.Now;
// 获取当前时间
DateTime dt2;
int
diff = 0;
while
(diff < i)
{
dt2 = DateTime.Now;
TimeSpan ts = dt2.Subtract(dt1);
diff = (
int
)ts.TotalSeconds;
Application.DoEvents();
}
}
I wrote it myself if (CTS. token.iscancellationrequested)
{
Console.WriteLine ("Thread is terminated! ");
Break
}
Application.doevents ();
C # WinForm program prevents front-end cards from dying