Lm th? no ? g?i m?t m?c cng vi?c v?i h? bi ch? ? b?ng cch s? d?ng Visual C#

D?ch tiu ? D?ch tiu ?
ID c?a bi: 315460 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

? Trang ny


Bi vi?t t?ng b?c ny cho b?n th?y lm th? no ? g?i m?t phng php ? bi s?i ? th?c hi?n.

Trong cc.NET mi tr?ng, qu tr?nh t?ng c m?t h? bi ch? ? m b?n c th? s? d?ng ? ch?y phng php khng ?ng b?.

Yu c?u

Danh sch sau v?ch ra ?c ? ngh? ph?n c?ng, ph?n m?m, c s? h? t?ng m?ng v gi d?ch v? ?c yu c?u:
  • Microsoft Visual Studio.NET ho?c Microsoft Visual Studio 2005
Bi vi?t ny gi? ?nh r?ng b?n ? quen thu?c v?i cc ch? ? sau:
  • Cc Visual C# ngn ng? l?p tr?nh

T?o m?t Visual C# Application c s? d?ng h? bi Thread

  1. B?t ?u Microsoft Visual Studio.NET ho?c Microsoft Visual Studio 2005.
  2. T?o m?t d? n Visual C# Windows ?ng d?ng m?i ?c ?t tn PoolDemo.
  3. S? d?ng h?p cng c? ? thm m?t Nt ki?m sot m?u. Tn m?c ?nh cho cc Nt ki?m sot l button1.
  4. Nh?p chu?t ph?i vo bi?u m?u v b?m Xem m?.
  5. Dn sau y b?ng cch s? d?ng ch? th? sau khi hi?n t?i b?ng cch s? d?ng ch? th?, nhng tr?c khi tuyn b? c?a cc PoolDemo khng gian tn:
    using System.Threading;
  6. Chuy?n v? thi?t k? xem, v sau b?m p chu?t button1. Dn o?n m? sau trong cc button1_Click x? l? s? ki?n:
    private void button1_Click(object sender, System.EventArgs e)
    	WaitCallback wcb = new WaitCallback(GetSysDirSize);
    		MessageBox.Show("The work item has been placed on the queue");
    	catch (Exception ex)
    		MessageBox.Show("Error: " + ex.Message);
  7. Dn o?n m? sau trong c th? c?a cc Form1 l?p h?c. Cc GetSysDirSize phng php tnh ton t?ng s? byte ?c lu tr? trong th m?c h? th?ng. GetSysDirSize cc cu?c g?i m?t phng php ?t tn l DirSize ? th?c hi?n tnh ton.

    LU ?: Nhi?m v? ny c th? m?t m?t th?i gian ? ch?y.
    private void GetSysDirSize(object state)
    	long total_length = DirSize(Environment.SystemDirectory);
    	this.Text = total_length.ToString();
    private long DirSize(string path)
    	long sz = 0;
    	System.IO.DirectoryInfo d = new System.IO.DirectoryInfo(path);
    	// List files.
    	foreach(System.IO.FileInfo f in d.GetFiles())
    		sz += f.Length;
    	// Recurse into directories.
    	foreach(System.IO.DirectoryInfo dx in d.GetDirectories())
    		sz += DirSize(dx.FullName);
    	return sz;

Ki?m tra cc m?u

  1. Nh?n CTRL + F5 ? ch?y cc ?ng d?ng.
  2. Khi cc h?nh th?c xu?t hi?n, nh?p vo nt. Khi cc M?c cng vi?c ? ?c ?t trn x?p hng h?p thng bo xu?t hi?n, nh?p vo Ok ? b? qua h?p th v tr? v? m?u chnh. Sau khi m?t s? ch?m tr? ng?n, kch th?c t?ng s? t?p tin trong th m?c h? th?ng ?c hi?n th? trong cc ch thch c?a bi?u m?u. Chi?u di c?a s? ch?m tr? ph? thu?c vo t?c ? c?a my tnh c?a b?n v s? l?ng cc t?p tin trong th m?c h? th?ng. Tnh ton kch th?c t?p tin di?n ra trn m?t s?i trong h? bi s?i.

Thu?c tnh

ID c?a bi: 315460 - L?n xem xt sau cng: 27 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft Visual C# 2005 Express Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
T? kha:
kbhowtomaster kbsample kbthread kbmt KB315460 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:315460

Cung cp Phan hi


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com