How the Execution Timeout is managed in ASP.NET

As you are probably aware, it is possible to specify the execution timeout of an ASP.NET request through the config file. All you need to do is to set the executionTimeout attribute on the httpRuntime element in either the web.config (for one ASP.NET application) or even the machine.config (to affect all ASP.NET applications):

<httpRuntime executionTimeout="200"/>

According to the online documentation the executionTimeout is a TimeSpan attribute that “specifies the maximum number of seconds that a request is allowed to execute before being automatically shut down by ASP.NET”. (BTW, it doesn’t work in debug mode)

The default value for this attribute has been set to 90 seconds in ASP.NET 1.x and was increased to 110 seconds in ASP.NET 2.0 or above.

Internally the timeout is managed by a timer (an instance of a System.Threading.Timer class) which is fired every 15 seconds.

Internally ASP.NET uses a Timer (an instance of System.Threading.Timer) to invoke the request cancelation process (As you are probably aware Thread.Abort() raises a ThreadAbortException in the thread on which it is invoked and the class responsible for this is System.Web.RequestTimeoutManager). This timer is fired once every 15 seconds, so if the executionTimeout is set to 3 seconds, in reality the request can timeout at any time between 3 seconds and 18 seconds.

When the timer is fired, a thread from the ThreadPool is used to check all the requests. The ones that have timed out are sent a ThreadAbortException by calling Abort on the thread executing the request.

So as per above, the executionTimeout only specifies the minimum duration that the request is guaranteed to be executed. The actual timeout can happen between executionTimeout and executionTimeout + 15 seconds.

Note: Keep in mind that ThreadAbortException can only be observed by managed code. So if you thread is calling some unmanaged functions, the thread will not be aborted, and therefore the timeout will not be enforced, until the execution returns to the managed world. That can be an arbitrary length of delay depending on what those unmanaged code does.



<httpRuntime executionTimeout="110"/> <!– default, Seconds–>

Sample Web Service Method (that you may use to test):


public string DoLongProcess()


//--- First Create the instance of Stopwatch Class

Stopwatch sw = new Stopwatch();

//--- Start The StopWatch ...From 000


bool complete = false;

var t = new Thread(() =>


bool toggle = false;

while (!complete) toggle = !toggle;




Thread.Sleep(500000); //Milli-seconds (Web config - 36000000)

complete = true;

t.Join(); // Blocks indefinitely

//--- Stop the Timer


//--- Writing Execution Time

string executionTimeTaken = string.Format("Minutes :{0}\nSeconds :{1}\n Mili seconds :{2}", sw.Elapsed.Minutes, sw.Elapsed.Seconds, sw.Elapsed.TotalMilliseconds);

return "Completed long process in (" + executionTimeTaken + ")";


PowerShell script to file browse, change file attribute, restore SharePoint site backup

Here is a nice little utility (written using PowerShell script) which I use to restore a site backup time to time.

Some features of this script are:

1. Displays a file browse dialog to select a file (see – Invoke-FileBrowser)

2. Removes the read-only attribute on the file (see – Remove-Readonly), this is required as the backup file is stored in TFS.

3. Restore a given backup file, without asking for confirmation (see – Restore-SPBackup)


$ErrorActionPreference = "Stop"

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0

# Example:
# $file = Invoke-FileBrowser -Title "Select a file" -Directory "D:\backups" -Filter "Powershell Scripts|(*.ps1)"
function Invoke-FileBrowser
      param([string]$Title,[string]$Directory,[string]$Filter="All Files (*.*)|*.*")
      [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
      $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog
      $FileBrowser.InitialDirectory = $Directory
      $FileBrowser.Filter = $Filter
      $FileBrowser.Title = $Title
      $Show = $FileBrowser.ShowDialog()
      If ($Show -eq "OK")
            Return $FileBrowser.FileName
            Write-Error "Restore cancelled by user."

# Example:
# Remove-Readonly -FilePath "D:\backups\filename.txt"
function Remove-Readonly
    #Remove read-only attribute, otherwise access denied error.
    Set-ItemProperty -Path $FilePath -name IsReadOnly -value $false

# Example:
# Restore-SPBackup -FilePath "D:\backups\backupfile.bak"
function Restore-SPBackup
    param([string]$BackupFilePath, [string]$WebUrl)
    #Restore the backup without asking for confirmation.
    Restore-SPSite -Identity $WebUrl -Path $BackupFilePath -Confirm:$false

$backupLocation = "C:\mywork\scm\JRCP.Internet\JRCP.Internet\JRCP Data Structures\Site Backups"
$SiteUrl = "http://sp2010riyaz:4040"

$file = Invoke-FileBrowser -Title "Browse" -Directory $backupLocation -Filter "All Files (*.*)|*.*"
Remove-Readonly -FilePath $file
Restore-SPBackup -BackupFilePath $file -WebUrl $SiteUrl

Wait for more useful utilities…