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