c# - How to get the parameters passed to the asynchronous method in the callback (not lambda) -
possible duplicate:
how parameters passed asynchronous method in callback
i need convert lambda method callback
var sendregistrationdelegate = new asyncsendregistrationdelegate(asyncsendregistrationmethod); sendregistrationdelegate.begininvoke(registrationtouser, label, ar => { var responcefromserver = sendregistrationdelegate.endinvoke(ar); if (responcefromserver.iserror) { settext(label, registrationtouser.name + @" " + responcefromserver.errormessage); } else { settext(label, registrationtouser.name + @" " + responcefromserver.data); } }, null);
first, have grasp on lambdas , anonymous delegates?
in snippet:
sendregistrationdelegate.begininvoke(registrationtouser, label, ar => // start of method { var responcefromserver = sendregistrationdelegate.endinvoke(ar); if (responcefromserver.iserror) { settext(label, registrationtouser.name + @" " + responcefromserver.errormessage); } else { settext(label, registrationtouser.name + @" " + responcefromserver.data); } } // end of method , null); ...the opening , closing { } mark beginning , ending of method, so:
void asynccallbackmethod(iasyncresult ar) { // method body } your begininvoke method like:
sendregistrationdelegate.begininvoke(registrationtouser, label, new asynccallback(asynccallbackmethod), null);
Comments
Post a Comment