c# - How the property isCompleted of IAsyncResult is updated? -
when call method asynchronously (using pattern beginxxx/endxxx), iasyncresult
result after calling beginxxx. how property "iscompleted" (in returning result variable) updated if neither method beginxxxx or endxxx have reference result variable?
ex:
// create delegate. asyncmethodcaller caller = new asyncmethodcaller(ad.testmethod); // initiate asychronous call. iasyncresult result = caller.begininvoke(3000, out threadid, null, null); // poll while simulating work. while(result.iscompleted == false) { thread.sleep(250); console.write("."); }
begininvoke
returning iasyncresult
have reference it. internally created , sent you.
for example, beginread
in filestream creates filestreamasyncresult
, returns it:
private unsafe filestreamasyncresult beginreadcore(byte[] bytes, int offset, int numbytes, asynccallback usercallback, object stateobject, int numbufferedbytesread) { nativeoverlapped* overlappedptr; filestreamasyncresult ar = new filestreamasyncresult { _handle = this._handle, _usercallback = usercallback, _userstateobject = stateobject, _iswrite = false, _numbufferedbytes = numbufferedbytesread }; manualresetevent event2 = new manualresetevent(false); ar._waithandle = event2; ..... if (hr == 0x6d) { overlappedptr->internallow = intptr.zero; ar.callusercallback(); return ar; }
Comments
Post a Comment