"Go" "C # Use the background to dynamically load data" Winform "anti-interface card dead" "BackgroundWorker" class

Source: Internet
Author: User

Using System.ComponentModel

Direct use of the Egprogressbar method

BackgroundWorker Bw =NewBackgroundWorker (); ListView ListView1=NewListView ();  Public voidEgprogressbar () {DirectoryInfo di=NewDirectoryInfo (@"c:/windows"); Fileinfo[] fi=di.            GetFiles (); Progressbar1.maximum= fi. Length-1;//set the maximum value of the progress barBw.workersupportscancellation =true; Bw.workerreportsprogress=true; Bw.dowork+=NewDoworkeventhandler (ADD);//Binding EventsBw.progresschanged + =NewProgresschangedeventhandler (Progress); Bw.runworkercompleted+=NewRunworkercompletedeventhandler (END);        Bw.runworkerasync (); }         Public voidADD (Objectsender, DoWorkEventArgs e) {DirectoryInfo di=NewDirectoryInfo (@"c:/windows"); foreach(FileInfo Iteminchdi. GetFiles ()) {ListViewItem LVT=NewListViewItem ();//use ListViewItem to store information that gets to a fileLvt. Text =item.                FullName; Lvt.                SubItems.Add (DateTime.Now.ToLongTimeString ()); Thread.Sleep ( -); Bw.reportprogress (ListView1.Items.Count, LVT);//report The current progress, get to the first few files and the file information            }        }         Public voidProgress (Objectsender, ProgressChangedEventArgs e) {progressBar1.Value= E.progresspercentage;//get the first few files to change the progress of the progress barListViewItem LV = e.userstate asListViewItem; LISTVIEW1.ITEMS.ADD (LV);//Add the newly acquired file information to the ListView        }         Public voidEnd (Objectsender, Runworkercompletedeventargs e) {progressBar1.Value=0;//progress bar Clear 0}

Pass-through method parameter RunWorkerAsync (parameter)

Get the e.argument of method DoWorkEventArgs

At the end of the decision DoWork method E.result automatically passed to completed E.result

"Go" "C # Use the background to dynamically load data" Winform "anti-interface card dead" "BackgroundWorker" class

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.