Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Background process in ASP.Net web Application

I want to execute some of the function in my web application without intimating the user about the running process just like background process in windows application.

I want to trigger background process when user click and want to send some data to these function too.

Can any one suggest me how this could be performed?

like image 890
Arjun Sharma Avatar asked Aug 08 '26 13:08

Arjun Sharma


1 Answers

private readonly BackgroundWorker backgroundWorker1 = new BackgroundWorker();

protected void Page_Load(object sender, EventArgs e)
    {
        this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
    }

    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
        try
        {
            timing();
        }
        catch
        {
        }
    }

    public void timing()
    {
        string tt = DateTime.Now.ToString("tt");
        string t = "";
        if (tt == "AM")
        {
            int hour = DateTime.Now.Hour;
            if ((hour >= 0) & (hour <= 11))
            {
                t = "GOOD MORNING";
            }
        }
        else if (tt == "PM")
        {
            int hour = DateTime.Now.Hour;
            if ((hour >= 12) & (hour <= 15))
            {
                t = "GOOD AFTERNOON";
            }
            else if ((hour >= 16) & (hour <= 23))
            {
                t = "GOOD EVENING";
            }
        }
        Label1.Text = t;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        backgroundWorker1.RunWorkerAsync();
    }


//SOURCE:

<%@ Page Language="C#" Async="true" AutoEventWireup="true" CodeFile="background.aspx.cs" Inherits="background" %> //Async="true"
like image 63
karthi Avatar answered Aug 11 '26 02:08

karthi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!