TimeoutException Klasse
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Die Ausnahme, die ausgelöst wird, wenn die für einen Prozess oder Vorgang zugewiesene Zeit abgelaufen ist.
public ref class TimeoutException : Exception
public ref class TimeoutException : SystemException
public class TimeoutException : Exception
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class TimeoutException : SystemException
public class TimeoutException : SystemException
type TimeoutException = class
inherit Exception
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type TimeoutException = class
inherit SystemException
type TimeoutException = class
inherit SystemException
Public Class TimeoutException
Inherits Exception
Public Class TimeoutException
Inherits SystemException
- Vererbung
- Vererbung
- Abgeleitet
- Attribute
Beispiele
Im folgenden Codebeispiel wird die Verwendung TimeoutException in Verbindung mit Membern der System.IO.Ports.SerialPort Klasse veranschaulicht.
// 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.
open System
open System.IO.Ports
try
// Set the COM1 serial port to speed = 4800 baud, parity = odd,
// data bits = 8, stop bits = 1.
let 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.
let input = sp.ReadLine()
sp.Close()
// Echo the input.
printfn $"{input}"
// Only catch timeout exceptions.
with :? TimeoutException as e ->
printfn $"{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.
Imports System.IO.Ports
Class Sample
Public Shared Sub Main()
Dim input As String
Try
' Set the COM1 serial port to speed = 4800 baud, parity = odd,
' data bits = 8, stop bits = 1.
Dim sp As 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 e As TimeoutException
Console.WriteLine(e)
End Try
End Sub
End Class
'
'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()
'
Hinweise
Informationen zum Festlegen des Timeoutintervalls vor dem Auslösen einer TimeoutException Ausnahme finden Sie in der Dokumentation zu dem Typ, dessen Methode timeout ausgeführt wurde. Informationen zum Behandeln des Timeouts finden Sie in der Dokumentation für die Methode, die die Ausnahme ausgelöst hat.
TimeoutException verwendet das HRESULT, COR_E_TIMEOUT, das den Wert 0x80131505 hat.
Eine Liste der anfänglichen Eigenschaftswerte für eine Instanz von TimeoutException, finden Sie unter den TimeoutException Konstruktoren.
Konstruktoren
| Name | Beschreibung |
|---|---|
| TimeoutException() |
Initialisiert eine neue Instanz der TimeoutException-Klasse. |
| TimeoutException(SerializationInfo, StreamingContext) |
Initialisiert eine neue Instanz der TimeoutException Klasse mit serialisierten Daten. |
| TimeoutException(String, Exception) |
Initialisiert eine neue Instanz der TimeoutException Klasse mit der angegebenen Fehlermeldung und inneren Ausnahme. |
| TimeoutException(String) |
Initialisiert eine neue Instanz der TimeoutException Klasse mit der angegebenen Fehlermeldung. |
Eigenschaften
| Name | Beschreibung |
|---|---|
| Data |
Ruft eine Auflistung von Schlüssel-Wert-Paaren ab, die zusätzliche benutzerdefinierte Informationen zur Ausnahme bereitstellen. (Geerbt von Exception) |
| HelpLink |
Dient zum Abrufen oder Festlegen eines Links zur Hilfedatei, die dieser Ausnahme zugeordnet ist. (Geerbt von Exception) |
| HResult |
Dient zum Abrufen oder Festlegen von HRESULT, einem codierten numerischen Wert, der einer bestimmten Ausnahme zugewiesen ist. (Geerbt von Exception) |
| InnerException |
Ruft die Exception Instanz ab, die die aktuelle Ausnahme verursacht hat. (Geerbt von Exception) |
| Message |
Ruft eine Nachricht ab, die die aktuelle Ausnahme beschreibt. (Geerbt von Exception) |
| Source |
Dient zum Abrufen oder Festlegen des Namens der Anwendung oder des Objekts, das den Fehler verursacht. (Geerbt von Exception) |
| StackTrace |
Ruft eine Zeichenfolgendarstellung der unmittelbaren Frames im Aufrufstapel ab. (Geerbt von Exception) |
| TargetSite |
Ruft die Methode ab, die die aktuelle Ausnahme auslöst. (Geerbt von Exception) |
Methoden
| Name | Beschreibung |
|---|---|
| Equals(Object) |
Bestimmt, ob das angegebene Objekt gleich dem aktuellen Objekt ist. (Geerbt von Object) |
| GetBaseException() |
Wenn sie in einer abgeleiteten Klasse überschrieben wird, wird die Exception Ursache einer oder mehrerer nachfolgenden Ausnahmen zurückgegeben. (Geerbt von Exception) |
| GetHashCode() |
Dient als Standardhashfunktion. (Geerbt von Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Wenn sie in einer abgeleiteten Klasse überschrieben wird, werden die SerializationInfo Informationen zur Ausnahme festgelegt. (Geerbt von Exception) |
| GetType() |
Ruft den Laufzeittyp der aktuellen Instanz ab. (Geerbt von Exception) |
| MemberwiseClone() |
Erstellt eine flache Kopie der aktuellen Object. (Geerbt von Object) |
| ToString() |
Erstellt und gibt eine Zeichenfolgendarstellung der aktuellen Ausnahme zurück. (Geerbt von Exception) |
Ereignisse
| Name | Beschreibung |
|---|---|
| SerializeObjectState |
Tritt auf, wenn eine Ausnahme serialisiert wird, um ein Ausnahmestatusobjekt zu erstellen, das serialisierte Daten zu der Ausnahme enthält. (Geerbt von Exception) |