When exporting an Excel file or a large amount of time-consuming computing, the front-end interface remains operable.

Source: Internet
Author: User

When exporting an Excel file or a large amount of time-consuming computing, the front-end interface remains operable.

Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. linq; using System. text; using System. threading; using System. windows. forms; namespace WinformTest {public partial class frmMain: Form {public frmMain () {InitializeComponent ();} # region use the thread // <summary> // export Excel or other time-consuming computing // </summary> // <param name = "sender"> </param >/// <param name = "e"> </param> private void btnExport_Click (object sender, eventArgs e) {// display the animation being calculated this. pictureBox1.Visible = true; // enable another Thread to finish exporting Thread t = new Thread (new ParameterizedThreadStart (Export); t. start ("SQL where ");} /// <summary> /// here, an example is provided with parameters. /// </summary> /// <param name = "strWhere"> </param> private void Export (object strWhere) {Thread. sleep (1000); this. invoke (new Action (UpdateUI);} private void UpdateUI () {this. pictureBox1.Visible = false;} # endregion # region uses the thread pool and returns the private void btnExportAnother_Click (object sender, EventArgs e) value {// displays the animation being calculated this. pictureBox1.Visible = true; // use the thread pool to export WaitCallback wc = new WaitCallback (this. exportExcel); ThreadPool. queueUserWorkItem (wc, "SQL where");} private void ExportExcel (object SQL) {Thread. sleep (1000); // here, the object result = this. invoke (new Func <int, int> (GetNumber), 11); MessageBox. show (result + "");} private int GetNumber (int num) {this. pictureBox1.Visible = false; return 1111 ;}# endregion private void btnTest_Click (object sender, EventArgs e) {MessageBox. show ("Interface available ");}}}

Source code

Related Article

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.