In the last few days, because we need to use the. NET pipeline, we found the relevant information on the Internet.
As a result, it is found that there are few network-related resources, and the implementation is basically based on the msdn article:
Http://msdn.microsoft.com/library/chs/default.asp? Url =/library/CHS/cpguide/html/cpconasynchronousprogrammingdesignpattern2.asp
This is normal. However, when I try to understand the procedure, I find that I cannot find any further information.
Next, I will explain my experiences on. NET development in the past few days:
I. Use the following methods to perform step-by-step failover in. Net:
Use thread) and custom methods with the same name as those used for commissioning (at this time, the Commission will automatically generate begininvoke ()).
Because I have only studied the latter, the following descriptions refer to the subsequent step tracing at the beginning of the latter.
2: The method used by the primary node is irrelevant to the method used by the primary node. It does not need to be used by the primary node for any special handling. Its right of determination lies in the caller.
3. Skip rows and returned results in skip steps: Use begininvoke to start the consumer and end the consumer with endinvoke to get the return value. Four methods are available:
1. Use the endinvoke () blocking method of the skip step directly at a synchronization point.
2. Use waithandle to wait for the completion of the complete step.
3. Complete the following steps by using deployment planner.
4. The callback method notification is completed when the previous step is complete.
4. After the two-day shopping spree, I had some questions:
1. I can see this in the msdn example: warning that endinvoke will be used when the non-synchronous consumer is used.
This method is described on msdn to retrieve the return values of asynchronous operations represented by the passed iasyncresult object.
But if I don't need to return the value in the skip step method, should I? Otherwise, it will cause "if the asynchronous operation has not been completed, this function will be blocked until the result is available ."
2. When waithandle is used, I am confused about the meanings of the colored mark sentence in the current section?
Since endinvoke will wait for the blocked action, why should we add an AR. asyncwaithandle. waitone ()? Public class asyncmain {
Static void main (string [] ARGs ){
Int threadid;
Asyncdemo ad = new asyncdemo ();
Asyncdelegate dlgt = new asyncdelegate (Ad. testmethod );
Iasyncresult AR = dlgt. begininvoke( 3000, out threadid, null, null );
Thread. Sleep (0 );
Console. writeline ("main thread {0} does some work .",
Appdomain. getcurrentthreadid ());
Ar. asyncwaithandle. waitone ();
String ret = dlgt. endinvoke (Out threadid, AR );
Console. writeline ("the call executed on thread {0}, with return value \" {1} \ ".", threadid, RET );
}
}
3. I added the endinvoke method in the callback method. However, during the response and during the operation, I found that this statement has not been replaced. As shown in the following code, it will end after the sentence is replaced by the background color. It will only enter the callback method when I wait for the full-time processing of the complete failover method on the background color. Is this normal? Public void asynchandle (iasyncresult IAR)
{
If (IAR. iscompleted)
{
Console. writeline ("async handle found the async is end! ");
Asyncall AC = (asyncall) IAR. asyncstate;
AC. endinvoke (IAR );
}
}
[Stathread]
Public static void main ()
{
Async2 x = new async2 ();
Console. writeline ("now is:" + system. datetime. Now );
Asyncall AC = new asyncall (X. myasync );
Asynccallback ACB = new asynccallback (X. asynchandle); // define handle
Iasyncresult IAR = ac. begininvoke (6000, ACB, AC); // start the next step and hand it over to handle.
X. mymethod1 (2000 );
Console. writeline ("-- the main method was ended at:" + system. datetime. Now );
}
We welcome your comments or questions.
Due to the short learning time and insufficient personal information, this article is not correct!