.net - TaskCreationOptions for an async Task Method -


i have method returning async task. wish call i'd customise taskcreationoptions sent it, i'm trying work out best practise this, or how should modify approach?

sample..

void main(){             _runtask=test(); // wish provide creation options here, ie longrunning, , possibly cancellation token } async task test() {     await task.delay(10); } 

i wish provide creation options here, ie longrunning, , possibly cancellation token

you can't customize taskcreationoptions on task object returned async method. essentially, doesn't make sense: don't create initial task here, task.delay does. can think of this:

task test() {     var scheduler = synchronizationcontext.current != null ?         taskscheduler.fromcurrentsynchronizationcontext() :         taskscheduler.current;      return task.delay(10).continuewith((t) => { },          cancellationtoken.none,         taskcontinuationoptions.none, scheduler); } 

now, that's possible control taskcontinuationoptions task returned continuewith (including taskcontinuationoptions.longrunning), not taskcreationoptions.

you can provide cancellation token:

async task test(cancellationtoken token) {     await task.delay(10, token);     // ...     token.throwifcancellationrequested(); } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -