Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long-running Asynchronous Thread in WCF

There is a WCF Service with a long-running Asynchronous Thread. This long-running operation can run more then 1 day. We are hosting WCF Service on IIS 6.

The Thread is running OK, but in 20 minutes we are receiving error message:
"Thread has been aborted"

The Thread is dead as a result.

Our WCF Service configuration:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single)]

Can you suggest the source of this problem?

Thank you for you answers.

like image 620
Artur Okolity Avatar asked Dec 18 '10 10:12

Artur Okolity


3 Answers

If there's no activity (no requests) to this web service IIS might decide to unload the application domain which of course will result in killing all threads. The default value is 20 minutes and could be configured in the properties of the application pool in IIS. There are also other factors that might cause the app pool to be recycled such as system running on low memory. So hosting such thing in IIS might not be reliable. You might consider hosting long running tasks in Windows Services.

like image 81
Darin Dimitrov Avatar answered Oct 04 '22 22:10

Darin Dimitrov


IIS6 has a setting that will shut down the app pool after a predefined time with no requests, the default is 20 minutes. It seems like that is what you are running into. You can find this setting under App Pool properties => Performance Tab => Remove checkmark in "Shutdown worker processes after being idle for".

In general, it is considered a bad idea to host long-running tasks under IIS, since there are many things that may abort the thread or shutdown the process altogether. Application Pool recycles being the most prominent one.

like image 43
driis Avatar answered Oct 04 '22 20:10

driis


You could have a Windows Service host a WCF endpoint that kicks off your long running task. Windows Services are meant to be running a long, long time and are ideal for this situation.

like image 29
ajawad987 Avatar answered Oct 04 '22 20:10

ajawad987