Note: The method is queued for execution,WaitcallbackIndicates the method to be executed. If the method is successfully queuedTrueOtherwiseFalse.
Example: The addtest method takes a long time to respond, so after the button#click is clicked,ProgramThe response will be lost. After threadpool. queueuserworkitem is used, the page will continue to respond to other times. After addtest is executed, the response will be returned.
< Window X: Class = "Wpfappthread. window1"
Xmlns = "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "Http://schemas.microsoft.com/winfx/2006/xaml"
Title = "Window1" Height = "300" Width = "300" >
< Grid >
< Button Height = "23" Horizontalalignment = "Left" Margin = "9, 23, 0, 0" Name = "Button1" Verticalalignment = "TOP" Width = "75" Click = "Button#click" > Buttonone </ Button >
< Button Height = "23" Margin = "102,23, 101,0" Name = "Button2" Verticalalignment = "TOP" Click = "Button2_click" > Buttontwo </ Button >
</ Grid >
</ Window >
Private Void Button#click ( Object Sender, routedeventargs E)
{
Threadpool. queueuserworkitem ( New Waitcallback (addtest ), " Testaa " );
// Addtest ();
}
Private Void Addtest ( Object Aa)
{
Long Result = 0 ;
For ( Int I = 0 ; I < 1000000000 ; I ++ )
{
Result + = I;
}
MessageBox. Show (result. tostring () + AA. tostring ());
}
Private VoidButton2_click (ObjectSender, routedeventargs E)
{
MessageBox. Show ("Two");
}