|
-
Mar 20th, 2015, 03:41 AM
#1
Thread Starter
Frenzied Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|