0

I have a web service hosted in IIS 7.5. The web service works fine. I try to configure a timeout in the web.config, but I can't do it. I tried in my web.config :

<Configuration>
<system.web>
<compilation debug="false" targetFramework="4.8" />
<httpRuntime targetFramework="4.8" executionTimeout="10" /> <!-- 10 seconds -->
<sessionState timeout="2" /> <!-- 2 minutes -->
</system.web>
</Configuration>

and in the web service controller :

Thread.Sleep(180000) //3 minutes

I thought the execution would stop after 10 seconds but instead it stops after 1 minute, whatever I put in the "executionTimeout" and "timeout" parameters. I have searched in IIS but impossible to find what this minute corresponds to.

Does someone have an idea ?

rene
  • 41,474
  • 78
  • 114
  • 152
eric.bryan
  • 51
  • 1
  • 8

2 Answers2

0

IIS timeout or httpruntime execution timeout won' t be able to kill a sleeping thread.

As you can see, thread sleep won't be limited by IIS

enter image description here

To make execution timeout work, you need to do actural process instead of a thread sleep.

So if you need to achieve this, please try something like this in your code.

thread.Start();
            thread.Join(1500);
            thread.Abort();

Or use CancellationTokenSource() and CancelAfter(10000).

https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/cancel-async-tasks-after-a-period-of-time

Jokies Ding
  • 3,374
  • 1
  • 5
  • 10
0

Jokies Ding : Thanks for the CancellationToken. You showed me the way. And thanks to this link : How to stop a thread if thread takes too long I use tasks which are more clean than raw threads.