WinForm loading data to the interface asynchronously

Source: Internet
Author: User

Make a study record.

There are two requirements:

1. Click the button to load the data asynchronously without stuttering the UI.

2. Load the acquired data onto the GridView.

For demand, the code is as follows:

 Public Delegate voidshowdatatabledelegate (DataTable DT); Private Async voidButton1_Click (Objectsender, EventArgs e) {                       //Way1.okThread T =NewThread (showdatatable); T.isbackground=true;                        T.start (); ////way2.ok.in. NET 4.5            //await Task.run (() = Showdatatable ());        }
     /// <summary>       ///If INITDT is placed in the BINDDT, it will also cause UI Kaka. Because the delegate method in invoke blocks the UI thread/// </summary>      Private voidshowdatatable () {DataTable dt= Initdt ();//time-consuming Operation//This . BeginInvoke (New Showdatatabledelegate (BINDDT), New Object[]{dt}); This. Invoke (NewShowdatatabledelegate (BINDDT),New Object[] {dt}); }
     Private voidBINDDT (DataTable dt) { This. Datagridview1.datasource =DT; }

WinForm loading data to the interface asynchronously

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.