none
Cancel a job with RX

    Question

  • I'm using RX to perform async task.

    This is my code:

    tokenSource = new CancellationTokenSource(); IDisposable subscription = Observable.Interval(TimeSpan.FromSeconds(0.3)).ObserveOnDispatcher().Subscribe( inp => { RaisePropertyChanged(() => EntriesCount); } ); tokenSource.Token.Register(() => {

    // it's the same code of Subscribe callback :-( IsProcessing = false; subscription.Dispose(); }); Observable.Start(() => { IsProcessing = true; ProcessFile(filename); } ).ObserveOnDispatcher().Subscribe( inp => {

    // it's the same code of token.Register callback :-( IsProcessing = false; subscription.Dispose(); }, tokenSource.Token );

    Since the code under Subscribe part is repeated on cancellation callback, I wonder if there is another way - in Rx - to have a callback at the end/cancellation of the job, instead of repeting the code twice as I did.

    Thank you !


    • Edited by F Starred Thursday, October 31, 2013 5:06 PM
    Thursday, October 31, 2013 5:02 PM

Answers

All replies