c# - Function Running Sync When VS Says it should be running async -


why b run sync? vs says ."because call not awaited, execution of current method continues before call completed." ;

a) task.factory.startnew(() => funcation(1, 1)); //runs async  b) funcation(1, 1); // says runs async in vs, runs sync. c)  var handleone = task.run(() =>         {             funcation(1, 1);         }); // runs async d) await task.factory.startnew(() => funcation(1, 1)); //awaits correctly e) await funcation(1, 1); //awaits correctly    static private async task<int> funcation(int x, int y)  {      task.delay(1000).wait();  } 

the funcation using async keyword not await in it's body run synchronously. function not compile.

a)

task.factory.startnew(() => funcation(1, 1)); //runs async 

here create thread , on thread call function asynchrounsly because running on thread.

b)

funcation(1, 1); 

function marked async not awaited invoked. in case compiler not check whether function using await in it's body or not (it has told on function declaration). check invoking asynchronous method without awaiting it.

c)

var handleone = task.run(() => { funcation(1, 1); }); // runs async 

i'm not sure on one, if knows happens here please help.

d)

await task.factory.startnew(() => funcation(1, 1)); //awaits correctly 

same a await created task , ok. bad idea create task run asynchronous operation.

e)

await funcation(1, 1); //awaits correctly 

do except else happens? it's way should use async , await.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -