TimeoutException (Clase)
.NET Framework 2.0
Nota: esta clase es nueva en la versión 2.0 de .NET Framework.
La excepción que se produce cuando ha caducado la hora asignada para un proceso u operación.
Espacio de nombres: System
Ensamblado: mscorlib (en mscorlib.dll)
System (Espacio de nombres)
Exception (Clase)
Ensamblado: mscorlib (en mscorlib.dll)
TimeoutException utiliza HRESULT, COR_E_TIMEOUT, que tiene el valor 0x80131505.
Para obtener una lista con los valores de propiedad iniciales de una instancia de TimeoutException, vea los constructores TimeoutException.
El ejemplo de código siguiente muestra el uso de TimeoutException junto con los miembros de la clase System.IO.Ports.SerialPort.
// 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()
*/
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter Edition
.NET Framework no admite todas las versiones de cada plataforma. Para obtener una lista de las versiones admitidas, vea Requisitos del sistema.
Referencia
TimeoutException (Miembros)System (Espacio de nombres)
Exception (Clase)
Otros recursos
Controlar y generar excepciones
Contenido de la comunidad
Agregar