C # winform UI asynchronous Delegation

Source: Internet
Author: User
1   Public   Class  Uisync  2   {  3           Private   Static  Isynchronizeinvoke sync;  4   5           Public   Static   Void  Init (isynchronizeinvoke sync)  6  {  7 Sync = Sync;  8   }  9   10           Public   Static   Void  Execute (action Action)  11   {  12 Sync. begininvoke (action, Null  ); 13   }  14   }  15   16       Public   Partial   Class  Form1: Form  17   {  18 Trackbar trackbar1 = New  Trackbar ();  19 Label lbltime =New  Label ();  20 Label lblduration = New  Label ();  21   22           Public  Form1 ()  23   {  24 Uisync. INIT ( This  );  25   } 26   27           Void Events_playerstopped ( Object  Sender, eventargs E)  28   {  29 Uisync. Execute () => Initcontrols ());  30   }  31   32           Void Events_mediaended ( Object Sender, eventargs E)  33   {  34 Uisync. Execute () => Initcontrols ());  35   }  36   37           Private   Void  Initcontrols ()  38   {  39 Trackbar1.value =0  ;  40 Lbltime. Text = "  00:00:00  "  ;  41 Lblduration. Text = "  00:00:00  "  ;  42   }  43   44          Void Events_timechanged ( Object  Sender, eventargs E)  45   {  46 Uisync. Execute () => lbltime. Text = timespan. frommilliseconds (datetime. Now. millisecond). tostring (). substring ( 0 , 8  ));  47   }  48   49           Void Events_playerpositionchanged ( Object  Sender, eventargs E)  50   {  51 Uisync. Execute () => trackbar1.value = ( Int )( 88 * 100  ));  52   }  53   54   55           Void Events_durationchanged ( Object  Sender, eventargs E)  56   {  57 Uisync. Execute () => lblduration. Text = timespan. frommilliseconds (datetime. Now. millisecond). tostring (). substring ( 0 , 8  ));  58   }  59 }

 

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.