i need to run a background operation on a ASP.NET 4.8 website placed in IIS, this is how i do it
public static void AddTaskToClient(int taskId, int clientId)
{
var t = new Task(async () =>
{
try
{
MyGlobalStorage[taskId].Status = StatusEnum.Running;
ResultsResponse res;
using (var wcf = new RfsnCallBack())
res = await wcf.CallWithCBAsync(() => wcf.client.ReadFilesAndSendNotificationsToClient(clientId));
MyGlobalStorage[taskId].ResultData = res;
MyGlobalStorage[taskId].Status = StatusEnum.Done;
}
catch (Exception ex)
{
MyGlobalStorage[taskId].Error = $"Failed to processing (clientId: {clientId}): {ex.Message}";
MyGlobalStorage[taskId].Status = StatusEnum.Failed;
}
});
HostingEnvironment.QueueBackgroundWorkItem(ct => t);
}
but the task never starts this way. How to solve this?