Redirect to action after finishing background task queue
I'm working on a .Net core solution that takes backup of storage files from another microservice and because this process takes too long time, we decided to build this routine under a background task.By following this link:
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-2.1
I have implemented the background by using Queued background tasks like the following :
public interface IBackgroundTaskQueue
void QueueBackgroundWorkItem(Func<CancellationToken, Task> workItem);
Task<Func<CancellationToken, Task>> DequeueAsync(
CancellationToken cancellationToken);
public class BackgroundTaskQueue : IBackgroundTaskQueue
private ConcurrentQueue<Func<CancellationToken, Task>> _workItems =
new ConcurrentQueue<Func<CancellationToken, Task>>();
private SemaphoreSlim _signal = new SemaphoreSlim(0);
public void QueueBackgroundWorkItem(
Func<CancellationToken, Task> workItem)
if (workItem == null)
throw new ArgumentNullException(nameof(workItem));
_workItems.Enqueue(workItem);
_signal.Release();
public async Task<Func<CancellationToken, Task>> DequeueAsync(
CancellationToken cancellationToken)
await _signal.WaitAsync(cancellationToken);
_workItems.TryDequeue(out var workItem);
return workItem;
public class QueuedHostedService : BackgroundService
private readonly ILogger _logger;
public QueuedHostedService(IBackgroundTaskQueue taskQueue,
ILoggerFactory loggerFactory)
TaskQueue = taskQueue;
_logger = loggerFactory.CreateLogger<QueuedHostedService>();
public IBackgroundTaskQueue TaskQueue get;
protected async override Task ExecuteAsync(
CancellationToken cancellationToken)
_logger.LogInformation("Queued Hosted Service is starting.");
while (!cancellationToken.IsCancellationRequested)
var workItem = await TaskQueue.DequeueAsync(cancellationToken);
try
await workItem(cancellationToken);
catch (Exception ex)
_logger.LogError(ex,
$"Error occurred executing nameof(workItem).");
_logger.LogInformation("Queued Hosted Service is stopping.");
}
and in the controller action method I did that:
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult TakeBackup()
// Process #1: update latest backup time in setting table.
var _setting = _settingService.FindByKey("BackupData");
var data = JsonConvert.DeserializeObject<BackUpData>(_setting.Value);
data.LatestBackupTime = DateTime.UtcNow;
_setting.Value = JsonConvert.SerializeObject(data);
_settingService.AddOrUpdate(_setting);
// Process #2: Begin a background service to excaute the backup task.
_queue.QueueBackgroundWorkItem(async token =>
// instead of this staff I will replace by the API I want to consume.
var guid = Guid.NewGuid().ToString();
for (int delayLoop = 0; delayLoop < 3; delayLoop++)
_logger.LogInformation(
$"Queued Background Task guid is running. delayLoop/3");
await Task.Delay(TimeSpan.FromSeconds(5), token);
_logger.LogInformation(
$"Queued Background Task guid is complete. 3/3");
// Here I need to redirect to the index view after the task is finished (my issue) ..
RedirectToAction("Index",new progress="Done");
);
return RedirectToAction("Index");
}
The logger information displays successfully
All what I need is to find away to be able to reload the index controller after the background task is done successfully but for some reason I don't know it can't be redirected.
The Index action method is like that :
public async Task<IActionResult> Index()
var links = new List<LinkObject>();
var files = await _storageProvider.GetAllFiles(null, "backup");
foreach (var f in files)
var file = f;
if (f.Contains("/devstoreaccount1/"))
file = file.Replace("/devstoreaccount1/", "");
file = file.TrimStart('/');
links.Add(new LinkObject()
Method = "GET",
Href = await _storageProvider.GetSasUrl(file),
Rel = f
);
return View(links);
Thanks !
c# asp.net-core asp.net-core-mvc asp.net-core-webapi background-task
|
show 1 more comment
I'm working on a .Net core solution that takes backup of storage files from another microservice and because this process takes too long time, we decided to build this routine under a background task.By following this link:
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-2.1
I have implemented the background by using Queued background tasks like the following :
public interface IBackgroundTaskQueue
void QueueBackgroundWorkItem(Func<CancellationToken, Task> workItem);
Task<Func<CancellationToken, Task>> DequeueAsync(
CancellationToken cancellationToken);
public class BackgroundTaskQueue : IBackgroundTaskQueue
private ConcurrentQueue<Func<CancellationToken, Task>> _workItems =
new ConcurrentQueue<Func<CancellationToken, Task>>();
private SemaphoreSlim _signal = new SemaphoreSlim(0);
public void QueueBackgroundWorkItem(
Func<CancellationToken, Task> workItem)
if (workItem == null)
throw new ArgumentNullException(nameof(workItem));
_workItems.Enqueue(workItem);
_signal.Release();
public async Task<Func<CancellationToken, Task>> DequeueAsync(
CancellationToken cancellationToken)
await _signal.WaitAsync(cancellationToken);
_workItems.TryDequeue(out var workItem);
return workItem;
public class QueuedHostedService : BackgroundService
private readonly ILogger _logger;
public QueuedHostedService(IBackgroundTaskQueue taskQueue,
ILoggerFactory loggerFactory)
TaskQueue = taskQueue;
_logger = loggerFactory.CreateLogger<QueuedHostedService>();
public IBackgroundTaskQueue TaskQueue get;
protected async override Task ExecuteAsync(
CancellationToken cancellationToken)
_logger.LogInformation("Queued Hosted Service is starting.");
while (!cancellationToken.IsCancellationRequested)
var workItem = await TaskQueue.DequeueAsync(cancellationToken);
try
await workItem(cancellationToken);
catch (Exception ex)
_logger.LogError(ex,
$"Error occurred executing nameof(workItem).");
_logger.LogInformation("Queued Hosted Service is stopping.");
}
and in the controller action method I did that:
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult TakeBackup()
// Process #1: update latest backup time in setting table.
var _setting = _settingService.FindByKey("BackupData");
var data = JsonConvert.DeserializeObject<BackUpData>(_setting.Value);
data.LatestBackupTime = DateTime.UtcNow;
_setting.Value = JsonConvert.SerializeObject(data);
_settingService.AddOrUpdate(_setting);
// Process #2: Begin a background service to excaute the backup task.
_queue.QueueBackgroundWorkItem(async token =>
// instead of this staff I will replace by the API I want to consume.
var guid = Guid.NewGuid().ToString();
for (int delayLoop = 0; delayLoop < 3; delayLoop++)
_logger.LogInformation(
$"Queued Background Task guid is running. delayLoop/3");
await Task.Delay(TimeSpan.FromSeconds(5), token);
_logger.LogInformation(
$"Queued Background Task guid is complete. 3/3");
// Here I need to redirect to the index view after the task is finished (my issue) ..
RedirectToAction("Index",new progress="Done");
);
return RedirectToAction("Index");
}
The logger information displays successfully
All what I need is to find away to be able to reload the index controller after the background task is done successfully but for some reason I don't know it can't be redirected.
The Index action method is like that :
public async Task<IActionResult> Index()
var links = new List<LinkObject>();
var files = await _storageProvider.GetAllFiles(null, "backup");
foreach (var f in files)
var file = f;
if (f.Contains("/devstoreaccount1/"))
file = file.Replace("/devstoreaccount1/", "");
file = file.TrimStart('/');
links.Add(new LinkObject()
Method = "GET",
Href = await _storageProvider.GetSasUrl(file),
Rel = f
);
return View(links);
Thanks !
c# asp.net-core asp.net-core-mvc asp.net-core-webapi background-task
Webprogramming and Multitasking do not mix that well. The Page Lifecycle demands that the page is send and dropped from memory ASAP. Multitasking would keep it in memory for a long time. msdn.microsoft.com/en-us/library/ms178472.aspx Any multitasking you are doing should be client side, outside of the webpage (a Webservice running in paralell), or both.
– Christopher
Nov 14 '18 at 3:55
Where is your "microservice" background task executing? Is kestrel spawning this process? Is your app running on IIS? Is this an Azure function or some other remote hosted function?
– Jim Yarbro
Nov 15 '18 at 8:18
I will call the API via http client inside QueueBackgroundWorkItem or that what I need.What I need is the ability to reload the page again after the queue is finished.To show the background process has been ended.
– Ahmed Elbatt
Nov 15 '18 at 8:21
@JimYarbro , I have a view with a button called [Take Backup] , by clicking on it a background task will be started graps data from extrenal microservice and once it finished I need just to update the user that the backup task is finished.I'm applying this on the view syntax by using a label that says "Process is in progress" and after the background task completed I will reload the view with a new query string return RedirectToAction("Index",new status="Done"); and in razor I will dedect the querystring and know that the background process is done.
– Ahmed Elbatt
Nov 15 '18 at 8:28
@FreedomDeveloper I believe you missed my question. Where is your "external microservice" running? See my previous question for various options.
– Jim Yarbro
Nov 15 '18 at 8:30
|
show 1 more comment
I'm working on a .Net core solution that takes backup of storage files from another microservice and because this process takes too long time, we decided to build this routine under a background task.By following this link:
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-2.1
I have implemented the background by using Queued background tasks like the following :
public interface IBackgroundTaskQueue
void QueueBackgroundWorkItem(Func<CancellationToken, Task> workItem);
Task<Func<CancellationToken, Task>> DequeueAsync(
CancellationToken cancellationToken);
public class BackgroundTaskQueue : IBackgroundTaskQueue
private ConcurrentQueue<Func<CancellationToken, Task>> _workItems =
new ConcurrentQueue<Func<CancellationToken, Task>>();
private SemaphoreSlim _signal = new SemaphoreSlim(0);
public void QueueBackgroundWorkItem(
Func<CancellationToken, Task> workItem)
if (workItem == null)
throw new ArgumentNullException(nameof(workItem));
_workItems.Enqueue(workItem);
_signal.Release();
public async Task<Func<CancellationToken, Task>> DequeueAsync(
CancellationToken cancellationToken)
await _signal.WaitAsync(cancellationToken);
_workItems.TryDequeue(out var workItem);
return workItem;
public class QueuedHostedService : BackgroundService
private readonly ILogger _logger;
public QueuedHostedService(IBackgroundTaskQueue taskQueue,
ILoggerFactory loggerFactory)
TaskQueue = taskQueue;
_logger = loggerFactory.CreateLogger<QueuedHostedService>();
public IBackgroundTaskQueue TaskQueue get;
protected async override Task ExecuteAsync(
CancellationToken cancellationToken)
_logger.LogInformation("Queued Hosted Service is starting.");
while (!cancellationToken.IsCancellationRequested)
var workItem = await TaskQueue.DequeueAsync(cancellationToken);
try
await workItem(cancellationToken);
catch (Exception ex)
_logger.LogError(ex,
$"Error occurred executing nameof(workItem).");
_logger.LogInformation("Queued Hosted Service is stopping.");
}
and in the controller action method I did that:
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult TakeBackup()
// Process #1: update latest backup time in setting table.
var _setting = _settingService.FindByKey("BackupData");
var data = JsonConvert.DeserializeObject<BackUpData>(_setting.Value);
data.LatestBackupTime = DateTime.UtcNow;
_setting.Value = JsonConvert.SerializeObject(data);
_settingService.AddOrUpdate(_setting);
// Process #2: Begin a background service to excaute the backup task.
_queue.QueueBackgroundWorkItem(async token =>
// instead of this staff I will replace by the API I want to consume.
var guid = Guid.NewGuid().ToString();
for (int delayLoop = 0; delayLoop < 3; delayLoop++)
_logger.LogInformation(
$"Queued Background Task guid is running. delayLoop/3");
await Task.Delay(TimeSpan.FromSeconds(5), token);
_logger.LogInformation(
$"Queued Background Task guid is complete. 3/3");
// Here I need to redirect to the index view after the task is finished (my issue) ..
RedirectToAction("Index",new progress="Done");
);
return RedirectToAction("Index");
}
The logger information displays successfully
All what I need is to find away to be able to reload the index controller after the background task is done successfully but for some reason I don't know it can't be redirected.
The Index action method is like that :
public async Task<IActionResult> Index()
var links = new List<LinkObject>();
var files = await _storageProvider.GetAllFiles(null, "backup");
foreach (var f in files)
var file = f;
if (f.Contains("/devstoreaccount1/"))
file = file.Replace("/devstoreaccount1/", "");
file = file.TrimStart('/');
links.Add(new LinkObject()
Method = "GET",
Href = await _storageProvider.GetSasUrl(file),
Rel = f
);
return View(links);
Thanks !
c# asp.net-core asp.net-core-mvc asp.net-core-webapi background-task
I'm working on a .Net core solution that takes backup of storage files from another microservice and because this process takes too long time, we decided to build this routine under a background task.By following this link:
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-2.1
I have implemented the background by using Queued background tasks like the following :
public interface IBackgroundTaskQueue
void QueueBackgroundWorkItem(Func<CancellationToken, Task> workItem);
Task<Func<CancellationToken, Task>> DequeueAsync(
CancellationToken cancellationToken);
public class BackgroundTaskQueue : IBackgroundTaskQueue
private ConcurrentQueue<Func<CancellationToken, Task>> _workItems =
new ConcurrentQueue<Func<CancellationToken, Task>>();
private SemaphoreSlim _signal = new SemaphoreSlim(0);
public void QueueBackgroundWorkItem(
Func<CancellationToken, Task> workItem)
if (workItem == null)
throw new ArgumentNullException(nameof(workItem));
_workItems.Enqueue(workItem);
_signal.Release();
public async Task<Func<CancellationToken, Task>> DequeueAsync(
CancellationToken cancellationToken)
await _signal.WaitAsync(cancellationToken);
_workItems.TryDequeue(out var workItem);
return workItem;
public class QueuedHostedService : BackgroundService
private readonly ILogger _logger;
public QueuedHostedService(IBackgroundTaskQueue taskQueue,
ILoggerFactory loggerFactory)
TaskQueue = taskQueue;
_logger = loggerFactory.CreateLogger<QueuedHostedService>();
public IBackgroundTaskQueue TaskQueue get;
protected async override Task ExecuteAsync(
CancellationToken cancellationToken)
_logger.LogInformation("Queued Hosted Service is starting.");
while (!cancellationToken.IsCancellationRequested)
var workItem = await TaskQueue.DequeueAsync(cancellationToken);
try
await workItem(cancellationToken);
catch (Exception ex)
_logger.LogError(ex,
$"Error occurred executing nameof(workItem).");
_logger.LogInformation("Queued Hosted Service is stopping.");
}
and in the controller action method I did that:
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult TakeBackup()
// Process #1: update latest backup time in setting table.
var _setting = _settingService.FindByKey("BackupData");
var data = JsonConvert.DeserializeObject<BackUpData>(_setting.Value);
data.LatestBackupTime = DateTime.UtcNow;
_setting.Value = JsonConvert.SerializeObject(data);
_settingService.AddOrUpdate(_setting);
// Process #2: Begin a background service to excaute the backup task.
_queue.QueueBackgroundWorkItem(async token =>
// instead of this staff I will replace by the API I want to consume.
var guid = Guid.NewGuid().ToString();
for (int delayLoop = 0; delayLoop < 3; delayLoop++)
_logger.LogInformation(
$"Queued Background Task guid is running. delayLoop/3");
await Task.Delay(TimeSpan.FromSeconds(5), token);
_logger.LogInformation(
$"Queued Background Task guid is complete. 3/3");
// Here I need to redirect to the index view after the task is finished (my issue) ..
RedirectToAction("Index",new progress="Done");
);
return RedirectToAction("Index");
}
The logger information displays successfully
All what I need is to find away to be able to reload the index controller after the background task is done successfully but for some reason I don't know it can't be redirected.
The Index action method is like that :
public async Task<IActionResult> Index()
var links = new List<LinkObject>();
var files = await _storageProvider.GetAllFiles(null, "backup");
foreach (var f in files)
var file = f;
if (f.Contains("/devstoreaccount1/"))
file = file.Replace("/devstoreaccount1/", "");
file = file.TrimStart('/');
links.Add(new LinkObject()
Method = "GET",
Href = await _storageProvider.GetSasUrl(file),
Rel = f
);
return View(links);
Thanks !
c# asp.net-core asp.net-core-mvc asp.net-core-webapi background-task
c# asp.net-core asp.net-core-mvc asp.net-core-webapi background-task
asked Nov 14 '18 at 3:24
Ahmed ElbattAhmed Elbatt
6841017
6841017
Webprogramming and Multitasking do not mix that well. The Page Lifecycle demands that the page is send and dropped from memory ASAP. Multitasking would keep it in memory for a long time. msdn.microsoft.com/en-us/library/ms178472.aspx Any multitasking you are doing should be client side, outside of the webpage (a Webservice running in paralell), or both.
– Christopher
Nov 14 '18 at 3:55
Where is your "microservice" background task executing? Is kestrel spawning this process? Is your app running on IIS? Is this an Azure function or some other remote hosted function?
– Jim Yarbro
Nov 15 '18 at 8:18
I will call the API via http client inside QueueBackgroundWorkItem or that what I need.What I need is the ability to reload the page again after the queue is finished.To show the background process has been ended.
– Ahmed Elbatt
Nov 15 '18 at 8:21
@JimYarbro , I have a view with a button called [Take Backup] , by clicking on it a background task will be started graps data from extrenal microservice and once it finished I need just to update the user that the backup task is finished.I'm applying this on the view syntax by using a label that says "Process is in progress" and after the background task completed I will reload the view with a new query string return RedirectToAction("Index",new status="Done"); and in razor I will dedect the querystring and know that the background process is done.
– Ahmed Elbatt
Nov 15 '18 at 8:28
@FreedomDeveloper I believe you missed my question. Where is your "external microservice" running? See my previous question for various options.
– Jim Yarbro
Nov 15 '18 at 8:30
|
show 1 more comment
Webprogramming and Multitasking do not mix that well. The Page Lifecycle demands that the page is send and dropped from memory ASAP. Multitasking would keep it in memory for a long time. msdn.microsoft.com/en-us/library/ms178472.aspx Any multitasking you are doing should be client side, outside of the webpage (a Webservice running in paralell), or both.
– Christopher
Nov 14 '18 at 3:55
Where is your "microservice" background task executing? Is kestrel spawning this process? Is your app running on IIS? Is this an Azure function or some other remote hosted function?
– Jim Yarbro
Nov 15 '18 at 8:18
I will call the API via http client inside QueueBackgroundWorkItem or that what I need.What I need is the ability to reload the page again after the queue is finished.To show the background process has been ended.
– Ahmed Elbatt
Nov 15 '18 at 8:21
@JimYarbro , I have a view with a button called [Take Backup] , by clicking on it a background task will be started graps data from extrenal microservice and once it finished I need just to update the user that the backup task is finished.I'm applying this on the view syntax by using a label that says "Process is in progress" and after the background task completed I will reload the view with a new query string return RedirectToAction("Index",new status="Done"); and in razor I will dedect the querystring and know that the background process is done.
– Ahmed Elbatt
Nov 15 '18 at 8:28
@FreedomDeveloper I believe you missed my question. Where is your "external microservice" running? See my previous question for various options.
– Jim Yarbro
Nov 15 '18 at 8:30
Webprogramming and Multitasking do not mix that well. The Page Lifecycle demands that the page is send and dropped from memory ASAP. Multitasking would keep it in memory for a long time. msdn.microsoft.com/en-us/library/ms178472.aspx Any multitasking you are doing should be client side, outside of the webpage (a Webservice running in paralell), or both.
– Christopher
Nov 14 '18 at 3:55
Webprogramming and Multitasking do not mix that well. The Page Lifecycle demands that the page is send and dropped from memory ASAP. Multitasking would keep it in memory for a long time. msdn.microsoft.com/en-us/library/ms178472.aspx Any multitasking you are doing should be client side, outside of the webpage (a Webservice running in paralell), or both.
– Christopher
Nov 14 '18 at 3:55
Where is your "microservice" background task executing? Is kestrel spawning this process? Is your app running on IIS? Is this an Azure function or some other remote hosted function?
– Jim Yarbro
Nov 15 '18 at 8:18
Where is your "microservice" background task executing? Is kestrel spawning this process? Is your app running on IIS? Is this an Azure function or some other remote hosted function?
– Jim Yarbro
Nov 15 '18 at 8:18
I will call the API via http client inside QueueBackgroundWorkItem or that what I need.What I need is the ability to reload the page again after the queue is finished.To show the background process has been ended.
– Ahmed Elbatt
Nov 15 '18 at 8:21
I will call the API via http client inside QueueBackgroundWorkItem or that what I need.What I need is the ability to reload the page again after the queue is finished.To show the background process has been ended.
– Ahmed Elbatt
Nov 15 '18 at 8:21
@JimYarbro , I have a view with a button called [Take Backup] , by clicking on it a background task will be started graps data from extrenal microservice and once it finished I need just to update the user that the backup task is finished.I'm applying this on the view syntax by using a label that says "Process is in progress" and after the background task completed I will reload the view with a new query string return RedirectToAction("Index",new status="Done"); and in razor I will dedect the querystring and know that the background process is done.
– Ahmed Elbatt
Nov 15 '18 at 8:28
@JimYarbro , I have a view with a button called [Take Backup] , by clicking on it a background task will be started graps data from extrenal microservice and once it finished I need just to update the user that the backup task is finished.I'm applying this on the view syntax by using a label that says "Process is in progress" and after the background task completed I will reload the view with a new query string return RedirectToAction("Index",new status="Done"); and in razor I will dedect the querystring and know that the background process is done.
– Ahmed Elbatt
Nov 15 '18 at 8:28
@FreedomDeveloper I believe you missed my question. Where is your "external microservice" running? See my previous question for various options.
– Jim Yarbro
Nov 15 '18 at 8:30
@FreedomDeveloper I believe you missed my question. Where is your "external microservice" running? See my previous question for various options.
– Jim Yarbro
Nov 15 '18 at 8:30
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292738%2fredirect-to-action-after-finishing-background-task-queue%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292738%2fredirect-to-action-after-finishing-background-task-queue%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Webprogramming and Multitasking do not mix that well. The Page Lifecycle demands that the page is send and dropped from memory ASAP. Multitasking would keep it in memory for a long time. msdn.microsoft.com/en-us/library/ms178472.aspx Any multitasking you are doing should be client side, outside of the webpage (a Webservice running in paralell), or both.
– Christopher
Nov 14 '18 at 3:55
Where is your "microservice" background task executing? Is kestrel spawning this process? Is your app running on IIS? Is this an Azure function or some other remote hosted function?
– Jim Yarbro
Nov 15 '18 at 8:18
I will call the API via http client inside QueueBackgroundWorkItem or that what I need.What I need is the ability to reload the page again after the queue is finished.To show the background process has been ended.
– Ahmed Elbatt
Nov 15 '18 at 8:21
@JimYarbro , I have a view with a button called [Take Backup] , by clicking on it a background task will be started graps data from extrenal microservice and once it finished I need just to update the user that the backup task is finished.I'm applying this on the view syntax by using a label that says "Process is in progress" and after the background task completed I will reload the view with a new query string return RedirectToAction("Index",new status="Done"); and in razor I will dedect the querystring and know that the background process is done.
– Ahmed Elbatt
Nov 15 '18 at 8:28
@FreedomDeveloper I believe you missed my question. Where is your "external microservice" running? See my previous question for various options.
– Jim Yarbro
Nov 15 '18 at 8:30