Search code examples
asp.netasp.net-4.5long-running-processes

Independent thread in Asp.net 4.5


protected void Button1_OnClick(object sender, EventArgs e)
{
    FineTuneDB();// Long Task running in db
    SendSMStoAllClients();// Using Twolio API to send sms to all client long task

    lblText.Text = "Button click is completed our system threads working on your request";
}

Is this possible that on button click I can response to client and independent long task going on separately.


Solution

  • If you don't care about whether task is completed or not, you call FineTuneDB method like this.

    Action fineTuneDB = FineTuneDB;
    fineTuneDB.BeginInvoke(null, null);
    

    Asynchronous Method Invocation

    Updated:

    Action<int, string> fineTuneDB = FineTuneDB;
    fineTuneDB.BeginInvoke((int)Session["id"], 
       Session["name"].ToString(), null, null);
    
    // Your method will be like this
    public void FineTuneDB(int id, string)
    {
    
    }