Asp.net asynchronous operations

Source: Internet
Author: User

/// <Summary>
/// Define the delegate
/// </Summary>
/// <Param name = "user"> User </param>
Delegate void makestaticdelegate (string user );

/// <Summary>
/// Here is the static test method.
/// </Summary>
/// <Param name = "user"> User </param>
Private Static void makestatictest (string user)
{
For (INT I = 0; I <10; I ++)
{
// Output the current variable
System. Console. writeline (User + ":" + I. tostring ());
System. Threading. thread. Sleep (1000 );
}
}

/// <Summary>
/// Here we simulate concurrent clicks by multiple users at the same time
/// </Summary>
Public void dotest ()
{

// The function called after the asynchronous operation is completed (asynccallback is a delegate)
Asynccallback Asyn = new asynccallback (SUCCESS );
// Simulate the concurrent operations of three users
Makestaticdelegate makestaticdelegate1 = new makestaticdelegate (makestatictest );
Makestaticdelegate1.begininvoke ("user1", Asyn, "SS ");
Makestaticdelegate makestaticdelegate2 = new makestaticdelegate (makestatictest );
Makestaticdelegate2.begininvoke ("user2", Asyn, "SS ");
Makestaticdelegate makestaticdelegate3 = new makestaticdelegate (makestatictest );
Makestaticdelegate3.begininvoke ("user3", Asyn, "SS ");
System. Console. Readline ();
}

Public void success (iasyncresult AR)
{< br> string Ss = ar. asyncstate. tostring (); // The obtained SS is makestaticdelegate1.begininvoke ("user1", Asyn, "SS "); the last parameter "SS" of this method should be converted to
console. write ("Call successful! ");
}

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.