Threadpool. queueuserworkitem method (waitcallback)

Source: Internet
Author: User

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");
}

 

 

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.