using (var bgw = new BackgroundWorker())
{
bgw.DoWork += delegate
{
System.Threading.Thread.Sleep(1000);
};
bgw.RunWorkerCompleted += async delegate
{
SystemInstancesTable savedLine = null;
savedLine = await Communication.CallAsync<SystemInstancesTable>("/api/Agent/GetDurableInstance", MethodEnum.POST, workflowGuid);
//insert into flowster retore points table the restore point
if (savedLine.BlockingBookmarks.StartsWith("FMSActivityApprovalWithValuesBookmarkResumed"))
{
//run LoadAndComplete
await LoadAndCompleteInstance(workflowGuid, parameters.TimestampId, parameters, tenantId, savedLine, sourceFromDesigner, savedLine.BlockingBookmarks, null, pendingWfId);
}
else
{
//run LoadAndComplete
await LoadAndCompleteInstance(workflowGuid, parameters.TimestampId, parameters, tenantId, savedLine, sourceFromDesigner, "", "", pendingWfId: pendingWfId);
}
};
bgw.RunWorkerAsync();
After some execution my code is not responding anymore. there is any problem whit my code?is the BackgroundWorker busy?
BackgroundWorkerdoesn't work well withasynccode. The modern way to do the same thing isTask.Run; see my blog series for an examination of whyTask.Runis better thanBackgroundWorkerin every scenario.A
Task.Run-based approach would look like this: