locked
Scheduling a task to run after each of two other tasks complete

    Question

  • Is there a way to schedule a task only after these two tasks with different return types are completed? One is IAsyncOperationWithProgress<int String^> and other returns task<StorageFile>. I need to run these two in parallel as this would save me a significant amount of time.?


    Parul Gupta

    Tuesday, June 18, 2013 2:01 PM

Answers

  • Tuesday, June 18, 2013 11:51 PM
    Owner
  • You can use Task.WhenAll to create a task that will complete when the two tasks complete (the first will need to be run through AsTask to convert into a Task).


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Wednesday, June 19, 2013 12:11 AM
  • But Task.WhenAll seems to have this restriction that all its tasks should have same return type. I need to get values from both of tasks, one of which returns int and other StorageFile.

    Parul Gupta

    Task.WhenAll returns a single Task, and can accept any Task (non-generic).  This means you can pass multiple Task<T> into it which are each a different type, without restriction, since they all derive from Task.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Wednesday, June 19, 2013 4:42 PM
  • One of the overrides of Task.WhenAll() takes a params array, which means you can just list as many comma-separated tasks that you want.

    Wednesday, June 19, 2013 8:24 PM

All replies

  • Tuesday, June 18, 2013 11:51 PM
    Owner
  • You can use Task.WhenAll to create a task that will complete when the two tasks complete (the first will need to be run through AsTask to convert into a Task).


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Wednesday, June 19, 2013 12:11 AM
  • But Task.WhenAll seems to have this restriction that all its tasks should have same return type. I need to get values from both of tasks, one of which returns int and other StorageFile.

    Parul Gupta

    Wednesday, June 19, 2013 1:27 PM
  • But Task.WhenAll seems to have this restriction that all its tasks should have same return type. I need to get values from both of tasks, one of which returns int and other StorageFile.

    Parul Gupta

    Task.WhenAll returns a single Task, and can accept any Task (non-generic).  This means you can pass multiple Task<T> into it which are each a different type, without restriction, since they all derive from Task.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Wednesday, June 19, 2013 4:42 PM
  • One of the overrides of Task.WhenAll() takes a params array, which means you can just list as many comma-separated tasks that you want.

    Wednesday, June 19, 2013 8:24 PM