Avoid false positives on the Interface [simple example]

Source: Internet
Author: User
Many of them have been written, as if they were, but they are not checked :)
Write down and save a backup for yourself.

Click private void button2_click (Object sender, eventargs E)
Dialogresult result = folderbrowserdialog1.showdialog ();

If (result = dialogresult. OK)
Textbox2.text = folderbrowserdialog1.selectedpath;

Thread thread = new thread (New threadstart (getfoldersizethread ));
Thread. Start ();

Long-time Data calculation function: Private ulong getfoldersize (string strfoldername)
Ulong result = 0;

Directoryinfo info = new directoryinfo (strfoldername );

Fileinfo [] arrfileinfo = info. getfiles ();

Foreach (fileinfo in arrfileinfo)
Result + = (ulong) fileinfo. length;

Directoryinfo [] arrdirinfo = info. getdirectories ();

Foreach (directoryinfo dirinfo in arrdirinfo)
Result + = getfoldersize (dirinfo. fullname );

Return result;

Thread method: Private void getfoldersizethread ()
Ulong longfoldersize = getfoldersize (textbox1.text );

Setlabelhandler handler = delegate (ulong size)
Label1.text = string. Format ("total size: {0: n} kb", size/1024 );

If (label1.invokerequired)
Invoke (handler, new object [] {longfoldersize });

Delegate: Public Delegate void setlabelhandler (ulong size );

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.