开发者

Keeping webservice alive if a spawned thread is still working

I have a webservice that will be called by a nightly job process documents, each document will be queued and executed on it's own background processor. This process can take a couple hours or a few munites depending on the load. I don't want to have it alive if it's not doing anything. But when a spawn a thread and return immediately the idle clock begins even though there is a thread working. i have not set the thread to IsBackground and it still terminates for being idle. For my test i set the idle time to be 1 minute. Is there a way to keep the service as being "ALIVE"

Here is the webservice code:

public class LetterInitiateWS : System.Web.Services.WebService
    {

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

        }

        private void ThreadExecuteBulkRun()
        {
            processor.ExecutBulkRun();
        }

    }


I think your best bet is to split this up into two seperate processes. You're going to have trouble with your IIS/ASP.NET based process and trying to keep it alive.

If I were you I'd look to do something like:

  1. Write a record into a DB/File/queue to signal the the long running thread must start.
  2. Have a windows service monitor the DB/file/queue for the signal and then begin the processing.

You'll find similar suggestions in the answers here:

Handling Web Service Timeouts While Performing Long-Running Database Tasks

Long running webservice architecture

Recommendations for designing a long-running, resource-intensive web service


For a solution which doesn't involve any coding, you can just disable IIS' inactivity monitor by changing the default Idle Time-out value of 20 minutes to 0. Go to Advanced Settings in your application pool and this is the second setting in the "Process Model" section.


To handle this I created a static class that when I am working in ThreadExecuteBulkRun the static class has a timer that every 5 minutes hist the webservice page which resets the Idle timer in IIS. and when the process completes the static class stops hitting the webpage.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜