this method calling in page load.
pageLoad:
protected void Page_Load(object sender, EventArgs e)
{
run_after_pageload();
}
my method:
public void run_after_pageload()
{
// code
}
this method calling in page load.
pageLoad:
protected void Page_Load(object sender, EventArgs e)
{
run_after_pageload();
}
my method:
public void run_after_pageload()
{
// code
}
in addition to use QueueBackgroundWorkItem (https://learn.microsoft.com/en-us/dotnet/api/system.web.hosting.hostingenvironment.queuebackgroundworkitem), you could use HttpTaskAsyncHandler, and make use of async, and use await Task.Delay(xxxx).
Something along these lines:
using System;
using System.Web;
using System.Threading.Tasks;
namespace PageLoadWithDelay
{
public class DelayedLoad : HttpTaskAsyncHandler
{
private int _delay = 1 * 1000;
public override async Task ProcessRequestAsync(HttpContext context)
{
var response = context.Response;
await LongRunningDatabaseOrNetworkTask(....);
await Task.Delay(_delay);
await LongRunningDatabaseOrNetworkTask(....);
}
public override bool IsReusable
{
get { return true; }
}
public override void ProcessRequest(HttpContext context)
{
throw new Exception("no implementation.");
}
}
}
and use this instead of a regular aspx page.
You should have a look at the System.Web.UI.Timer.
There are two options. Option one would be to use a timer. This would allow you to specify the time period and if need be the interval. If you are only running it once you can just disable the timer
Option two. use
System.Threading.Thread.Sleep(10000);
where the number in the sleep function is the time to wait in ms. 1000 ms = 1 second