I have a long task that runs, and can take up to 15 minutes, I allow the user to only run one at a time. This all works well but I can't get my results and have a cancel button. Currently I have the cancel button write a file, and if that file is present during a loop, the task completes and self deletes. However, I can't get the results of the task to do anything, so errors aren't reported or anything. What is your recommendation on doing this?
Libraries needed for below (iirc)
using System
using System.Threading
using System.Threading.Tasks
Here is a rough example of my execution code.
protected void Execute_Click(object sender, EventArgs e)
{
Task taskExecute = new Task(()=>
{
// 15 minute task
// I also look for cancelation file during loop periodically.
}
taskExecute.Start();
// If i wait for the task, it freezes the webpage so this is commented out
// taskExecute.Wait();
}
here is my cancelation code:
protected void Cancel_Click(object sender, EventArgs e)
{
//code to write file that long script looks for...
}
If you're wondering, the code is called via <asp:button onclick="Execute_Click">
calls. etc...
Also, I can click the cancel button if I refresh the page, but that defeats the purpose, as the responses in my results box won't be visible.