I have a asp.net web application, and in a form i use async process.
Task.Run(async () =>
{
foreach (ListItem item in cbListFaculties.Items)
{
if (item.Selected)
{
service.FinishSyncDepartment(actionId, item.Value);
}
}
});
But what i want to do is, if the Task has started and user hits that page again, i want to say, that task hasn’t stop yet, so you can’t continue.
How can i resolve this issue? Any idea?
Thanks.
You can create
Taskobject(instead of running it at once) and useIsCompletedproperty to check if it was completed. Or you can use some thread safe object (static field) to flag that task is busy.If you need the task to survive during page reloads – than you’ll have to save reference to that
Taskobject in some manner(cookie, session, static variable, viewstate, cache, database….)