Results 1 to 3 of 3

Thread: Help to implement task based algorithm

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    Help to implement task based algorithm

    Hi!

    I have really hit a wall. I need to figure out how to sync the execution and cancellation of tasks based on the following program flow:

    CASE WHEN STARTING APP
    ----------------------------------------
    1) User selects a category in UI

    2) Selected category is set to the new categoryID

    3) Data is loaded for the category in separate thread to avoid locking ui

    4) Finished


    CASE WHEN USER CHANGE CATEGORY WHEN 3) IS NOT FINISHED
    ----------------------------------------------------------------------

    1) Selected category is set to the new categoryID
    2) Check if data is being loaded
    3) If data is loaded cancel that data load
    4) Wait for cancel to finish
    5) When cancel is finished, load data for the new categoryid
    6) Finished

    CASE WHEN USER CHANGE CATEGORY WHEN 4) IS NOT FINISHED
    ---------------------------------------------------------------------------

    1) If cancellation is in progress...
    2) Set the new categoryID so it is ready when cancellation of task is finished and new task is starting.


    Basically, only ONE worker task can run at a time. If user decides to change category 5-6 times quickly the running one should be cancelled and NO other tasks start even if the user decides to change category during this time. I did a test with cancellationtokens, and they need to be handled in the LoadData( method, which contains multiple await calls to REST web UI. And between each of these awaits I check if cancellationrequested and throw an exception.


    I have spent the past days trying to implement the above using Task.Run and various COntinueWith combinations, but I fail to solve the issue on how to select which one to start once cancellation is finished.

    Is above prossible to realize using only Task and ContinueWith and CancellaitonToken? I don't want the UI to freeze in any way.

    Very puzzling...

    /H

  2. #2
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: Help to implement task based algorithm

    Why not just use a background worker?
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  3. #3
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,372

    Re: Help to implement task based algorithm

    how do you load the data and where is it coming from?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width