c# - How do you get the value from Func<t> called async? -
how value func<t>
called using begininvoke?
for example:
private void mytest() { func<string> foo = bar; foo.begininvoke(barcomplete, null); } private string bar() { return "success"; } private void barcomplete(iasyncresult ar) { var result = (string) ar.asyncstate; console.writeline(result); // should print "success" }
do have cast asynccallback , call endinvoke
?
anyways, feedback.
asyncstate
holds null
passed in 2nd parameter, should pass foo
object in instead. result must call endinvoke
foo object , return object version of result.
private void mytest() { func<string> foo = bar; foo.begininvoke(barcomplete, foo); } private string bar() { return "success"; } private void barcomplete(iasyncresult ar) { var foo = (func<string>)ar.asyncstate; var uncastresult = foo.endinvoke(ar); //this returns "object", still work writeline var castresult = (string)uncastresult; console.writeline(uncastresult); // should print "success" console.writeline(castresult); // should print "success" }
Comments
Post a Comment