c# - Async Method does not return control back to caller -
The main method is completely executed before the control When you If you do not want to use the return method when executing the operation, then execute synchronously if you are trying to do I / O is bound to function (like somebody Uploading something to the server), UploadToServer . Should I remove Task.Run () to UploadToServer or explicitly WaitAll ?
Public class uploader {Async public work & lt; Int & gt; Upload (int i) {int incremented = 0; Var t = UploadToServer (i); If (T! = Null) {incremented = await t; } Returns increased; } Async Private Tasks & lt; Int & gt; UploadsToSource (intI) {incremented = 0; Wait for the job. (() = & Gt; {//Console.ReadLine (); // actual upload operation extended = i + 1;}); Returns increased; }} Class program {static zero main (string [] args) {uploader appell = new uploader (); Var res = upl.upload (10). result; }} wait on Async methods, the control caller is provided back. What you are experiencing is the appropriate async behavior. Tasks. Do not use. , because I / O boundaries are naturally conveyed to async end points, this process requires unnecessary threads as an example, which shows a bunch of XXXAsync methods is.
Comments
Post a Comment