Refresh of the under WPF label

Source: Internet
Author: User

Under WPF, the Label control does not have any method of Refresh (). So now the question is coming.

Let's say there's a scenario where a button, a label, a button is pressed to trigger a time-consuming operation on a WPF form, and before the action, the label displays a message saying what to do now.

As a result, the button press down, the system will be busy, and the label should be displayed first, but did not show, until the time-consuming operation has been completed before the sudden display.

This is not science, completely lost the meaning of the hint. is clearly label. Content = "Try to connect with the server, please wait ..." "; Execution first, how the result is late.

The reason is not to delve into. I'm not interested in WPF either. WPF is so willful. The solution is to put time-consuming operations into a new thread:

Loginwindow Loginwin;
        Socketioclient client;
        Please wait while private void Button_Click (object sender, RoutedEventArgs e)
        {
            labinfo.content = "Try to connect to the server ..." ";
            btnlogin.isenabled = false;

            Thread thr = null;
            THR = new Thread (new ThreadStart (buildconnection));
            Thr. Priority = threadpriority.lowest;
            Thr. IsBackground = true;
            Thr. Start ();
        }
        void Buildconnection ()
        {
            client = new Socketioclient ();

            Client. onconnected + = login;
            Client. Onauthok + = Authok;

            Client. Execute ();
        }


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.