开发者

IIS thinks webservice is Idle

开发者 https://www.devze.com 2023-02-09 15:06 出处:网络
The issue is even though i set the threads as \" thrd.IsBackground = fals开发者_开发百科e\" iis does not consider it running even though this is a long running processs. If I don\'t turn off the idle

The issue is even though i set the threads as " thrd.IsBackground = fals开发者_开发百科e" iis does not consider it running even though this is a long running processs. If I don't turn off the idle shutdown for the application pool it will shut down because it thinks it's idle. As well if I deploy a new version it aborts all threads that are running instead of waiting for a true idle of the all processes before recyling and using new code. What am I doing wrong here? this is my webservice code:

  /// <summary>
    /// Summary description for LetterInitiateWS
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class LetterInitiateWS : System.Web.Services.WebService
    {

        private static Processor processor = new Processor();
        [WebMethod]
        public void ExecuteBulkRun()
        {
            var thrd = new Thread(() => ThreadExecuteBulkRun());
            thrd.IsBackground = false;
            thrd.Start();

        }

        [WebMethod]
        public void ExecuteTemplateBulkRun(string templateCategory, string TemplateType)
        {
            var thrd = new Thread(() => ThreadExecuteTemplateBulkRun(templateCategory, TemplateType));
            thrd.IsBackground = false;
            thrd.Start();

        }

        private void ThreadExecuteBulkRun()
        {
            processor.ExecuteBulkRun();
        }
        private void ThreadExecuteTemplateBulkRun(string templateCategory, string TemplateType)
        {
            processor.ExecuteTemplateBulkRun(templateCategory, TemplateType);
        }

    }
}


IIS isn't stable enough to run long-running processes. It's designed for request-response type interaction.

If you need to run something for a long time, run it in a Windows service. You can use remoting or a message queue to start it from your webservice.


One thing you might be able to do is hook into the Application_End event. At worst you could log which threads need to be completed and at best you might be able to setup a delay of some sort that kept the app alive until the threads completed.

0

精彩评论

暂无评论...
验证码 换一张
取 消