I got a requirement to implement a long running process in asynchronously. I have done the implementation using Task.Run() everything worked without any issues. However the requirement got changes and now they want 'cancel' feature of any ongoing async task. if I explained the requirement more simple form; I have a button, text box and a list box. when a user enter something in the text box and click on the button , it should fetch data from db and populate the list box with db results (assume this is a long running process) if the user change his mind and enter something again in the text box and click on the button, it should stop the current running task, clear the list box and should start the task (fetching and displaying data) with the new values entered in his second attempt.
I tried to use cancellation token for this but didn't get succeeded. I would be grateful if somebody can help me with this.