C # WinForm program prevents front-end cards from dying

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.