Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

TimeoutException Class

The exception that is thrown when the time allotted for a process or operation has expired.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public class TimeoutException : SystemException
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public class TimeoutException extends SystemException
SerializableAttribute 
ComVisibleAttribute(true) 
public class TimeoutException extends SystemException
Not applicable.

TimeoutException uses the HRESULT, COR_E_TIMEOUT, which has the value 0x80131505.

For a list of initial property values for an instance of TimeoutException, see the TimeoutException constructors.

The following code example demonstrates the use of TimeoutException in conjunction with members of the System.IO.Ports.SerialPort class.

// This example demonstrates the use of the TimeoutException 
// exception in conjunction with the SerialPort class.

using System;
using System.IO.Ports;

class Sample 
{
    public static void Main() 
    {
    string input;
    try 
        {
// Set the COM1 serial port to speed = 4800 baud, parity = odd, 
// data bits = 8, stop bits = 1.
        SerialPort sp = new SerialPort("COM1", 
                        4800, Parity.Odd, 8, StopBits.One); 
// Timeout after 2 seconds.
        sp.ReadTimeout = 2000;
        sp.Open();

// Read until either the default newline termination string 
// is detected or the read operation times out.
        input = sp.ReadLine();

        sp.Close();

// Echo the input.
        Console.WriteLine(input);
        }

// Only catch timeout exceptions.
    catch (TimeoutException e)
        {
        Console.WriteLine(e);
        }
    }
}
/*
This example produces the following results:

(Data received at the serial port is echoed to the console if the 
read operation completes successfully before the specified timeout period 
expires. Otherwise, a timeout exception like the following is thrown.)

System.TimeoutException: The operation has timed-out.
   at System.IO.Ports.SerialStream.ReadByte(Int32 timeout)
   at System.IO.Ports.SerialPort.ReadOneChar(Int32 timeout)
   at System.IO.Ports.SerialPort.ReadTo(String value)
   at System.IO.Ports.SerialPort.ReadLine()
   at Sample.Main()
*/

// This example demonstrates the use of the TimeoutException 
// exception in conjunction with the SerialPort class.

import System.*;
import System.IO.Ports.*;

class Sample
{
    public static void main(String[] args)
    {
        String input;
        try {
            // Set the COM1 serial port to speed = 4800 baud, parity = odd, 
            // data bits = 8, stop bits = 1.
            SerialPort sp = new SerialPort("COM1", 4800, Parity.Odd, 8,
                StopBits.One);
            // Timeout after 2 seconds.
            sp.set_ReadTimeout(2000);
            sp.Open();
            // Read until either the default newline termination string 
            // is detected or the read operation times out.
            input = sp.ReadLine();

            sp.Close();
            // Echo the input.
            Console.WriteLine(input);
        }
            // Only catch timeout exceptions.
        catch (TimeoutException e) {
            Console.WriteLine(e);
        }
    } //main
} //Sample

/*
This example produces the following results:

(Data received at the serial port is echoed to the console if the 
read operation completes successfully before the specified timeout period 
expires. Otherwise, a timeout exception like the following is thrown.)

System.TimeoutException: The operation has timed-out.
   at System.IO.Ports.SerialStream.ReadByte(Int32 timeout)
   at System.IO.Ports.SerialPort.ReadOneChar(Int32 timeout)
   at System.IO.Ports.SerialPort.ReadTo(String value)
   at System.IO.Ports.SerialPort.ReadLine()
   at Sample.main()
*/

System.Object
   System.Exception
     System.SystemException
      System.TimeoutException
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.