????? C# ?? ????? ?? ???? ????? ?? ????? ??? ?? ??? ???? ?? ????? ???? ?? ??? ???? ????

???? ?????? ???? ??????
???? ID: 315460 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

??????

?? ??? ?? ??? ???? ???? ???????? ?? ??? ????? ??? ?? ??? ?? ?????? ?? ????? ???? ?? ??? ???? ?????? ???

.NET ??????? ??? ???????? ????????? ??? ????? ??? ?? ????? ????? ?? asynchronously ??????? ?? ????? ?? ??? ?? ???? ????

??????????


????? ???? outlines ???????? ?????????, ??????????, ??????? ?????? ?? ?????? ??? ?? ???? ???:
  • Microsoft Visual Studio .NET ?? Microsoft Visual Studio 2005
?? ???? ????? ?? ?? ?? ????? ???? ?? ?????? ???:
  • ????? C# ???? ????????????

Create a Visual C# Application that Uses the Thread Pool

  1. Microsoft Visual Studio .NET ?? Microsoft Visual Studio 2005 ??????? ?????
  2. Create a new Visual C# Windows Application project named PoolDemo.
  3. Use the Toolbox to add a???????????? ???? ?? ??? ???????? The default name for the???control is button1.
  4. ??????? ?? ????-????? ????, ?? ???? ??? ????? ????????? ???.
  5. Paste the following?? ????? ????directive after the existing?? ????? ????directives, but before the declaration of thePoolDemo??? ?????:
    using System.Threading;
    					
  6. Switch back to Design view, and then double-clickButton1. ??? ????? ??? ???????button1_Click????? ??????:
    private void button1_Click(object sender, System.EventArgs e)
    {
    	WaitCallback wcb = new WaitCallback(GetSysDirSize);
    	try
    	{
    		ThreadPool.QueueUserWorkItem(wcb);
    		MessageBox.Show("The work item has been placed on the queue");
    	}
    	catch (Exception ex)
    	{
    		MessageBox.Show("Error: " + ex.Message);
    	}
    }
    					
  7. Paste the following code within the body of theForm1????? TheGetSysDirSizemethod calculates the total number of bytes that are stored in the system directory.GetSysDirSizecalls another method namedDirSizeto perform the calculation.

    ???:: ?? ????? ?? ????? ?? ??? ??? ??? ?? ???? ???
    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;
    }
    					

????? ???????

  1. ????????? ?? ????? ?? ??? CTRL + F5 ??????
  2. ?? ??????? ????? ???? ??, ' ??? ????? ????? ???????? ?? ????? ???? ????? ???? ??? ??????? ????? ????? ???? ??, ????? ????OK????? ????? ?? ?????? ????, ?? ????? ??????? ?? ???? ?????? ??? ???? ????? ?? ??? ?????? ?????????? ??? ??? ????? ???? ?????? ?? ??? ??? ????????? ???? ???? ??? ???? ?? ????? ???? ???????? ?? ?????? ?????????? ??? ??????? ?? ?????? ?? ??? ?? ?????? ???? ??? ???? ???? ?? ???? ????? ??? ??? ????? ?? ????? ???? ???

???

???? ID: 315460 - ????? ???????: 04 ?????? 2010 - ??????: 2.0
???? ???? ???? ??:
  • Microsoft Visual C# 2005 Express Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
??????: 
kbhowtomaster kbsample kbthread kbmt KB315460 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:315460

??????????? ???

 

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