Why is Global.asax -> Application_Start not called when replacing myapp.dll?

The bottom line is that there are tasks that are performed in ThreadPool . If you replace myapp.dll, a ThreadAbortException will be thrown. I wrote a small code to restart these tasks and call it in Global.asax -> Application_Start . But nothing happens.

How can this be realized?

here is the startup code

  public static void RunAllWorkingOrDivideTasks() { try { Task[] tasks = TaskDataManager.GetAllTasks(); if (tasks.Length > 0) foreach (Task task in tasks.Where(e => e.status == TaskStatus.active || e.status == TaskStatus.divide)) { ThreadPool.QueueUserWorkItem( new WaitCallback(delegate (object state) { Task(task.username, task.taskId); }), null); } } catch { } } 

    1 answer 1

    And where do you get some tasks when starting a web application?

    When replacing any binary, IIS restarts the web application. In ASP.NET, it looks like the application domain unloading (AppDomain). This operation, including, clears any static fields — including your list of unfinished tasks.

    Tasks, like any other data in a web application, should be stored in a database.


    Oh yeah: after the restart, the web application itself will not rise until the first request comes to it.

    Try this recipe from this answer: The first time you visit a site that is running on IIS, the site opens for a very long time.

    • Tasks store their status on disk locally. Task [] tasks = TaskDataManager.GetAllTasks (); gets all the states. delegate (object state) {Task (task.username, task.taskId); } Receives data and starts working with it in the pool. The question is whether Global.asax -> Application_Start () is called when a binary is replaced. - B. Harholinskiy
    • @ B.Harholinskiy seems to understand what you are having trouble with. See the update in response. - Pavel Mayorov