Con risposta Contination not trigered

  • Friday, January 18, 2013 9:51 PM
     
      Has Code

    Hi,

    I've a problem with a continuation never called :

    if i write 

    Task.Factory.StartNew(() =>
        {
            this.importedBatchClasses = this.LoadImportedBatchClass();
        })
        .ContinueWith(
                this.HandleFailedTask,
                CancellationToken.None,
                TaskContinuationOptions.OnlyOnFaulted,
                uiSynchronisation)
        .ContinueWith(
            previous => this.RefreshDisplayedProperties(index),
            CancellationToken.None,
            TaskContinuationOptions.None,
            uiSynchronisation)
        .ContinueWith(previous => this.RefreshCompletedEvent.Set())
    

    The RefreshCompletedEvent.Set is never called

    But if i write it like this:

    Task.Factory.StartNew(() =>
        {
            this.importedBatchClasses = this.LoadImportedBatchClass();
        })
        .ContinueWith(
                this.HandleFailedTask,
                CancellationToken.None,
                TaskContinuationOptions.OnlyOnFaulted,
                uiSynchronisation)
        .ContinueWith(previous => this.RefreshCompletedEvent.Set())
        .ContinueWith(
            previous => this.RefreshDisplayedProperties(index),
            CancellationToken.None,
            TaskContinuationOptions.None,
            uiSynchronisation)
    

    The RefreshCompletedEvent.Set is called.

    What's the difference between the twos ?

    I need the event to be setted in last 

    Thanks for any help

All Replies

  • Saturday, January 19, 2013 1:33 PM
     
     Answered
    Your first code works for me: the last continuation is called. Could you include short, but complete example code that shows your issue?
    • Marked As Answer by Minskaya Tuesday, January 22, 2013 4:29 PM
    •  
  • Tuesday, January 22, 2013 4:21 PM
     
     

    Thanks for your help.

    The issue occurs when the function is called from an unit test. I think the task is scheduled on the UT's thread which is blocked waiting the event.

    So I've change my mind,  and made an another way to not use an event.