TimeoutException Osztály
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Az a kivétel, amely akkor lesz kivetve, ha a folyamatra vagy műveletre vonatkozó idő lejárt.
public ref class TimeoutException : Exception
public ref class TimeoutException : SystemException
public class TimeoutException : Exception
public class TimeoutException : SystemException
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class TimeoutException : SystemException
type TimeoutException = class
inherit Exception
type TimeoutException = class
inherit SystemException
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type TimeoutException = class
inherit SystemException
Public Class TimeoutException
Inherits Exception
Public Class TimeoutException
Inherits SystemException
- Öröklődés
- Öröklődés
- Származtatott
- Attribútumok
Példák
Az alábbi példakód az osztály tagjaival TimeoutException való együttes használatát System.IO.Ports.SerialPort mutatja be.
// 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()
'
Megjegyzések
A kivétel kivédése előtti TimeoutException időtúllépési időköz beállításával kapcsolatos információkért tekintse meg annak a típusnak a dokumentációját, amelynek a metódusa időtúllépést eredményezett. Az időtúllépés kezelésével kapcsolatos információkért tekintse meg a kivételt okozó metódus dokumentációját.
TimeoutException A HRESULT COR_E_TIMEOUT, amelynek értéke 0x80131505.
A TimeoutException példány kezdeti tulajdonságainak listájáért tekintse meg a TimeoutException konstruktorokat.
Konstruktorok
| Name | Description |
|---|---|
| TimeoutException() |
Inicializálja a TimeoutException osztály új példányát. |
| TimeoutException(SerializationInfo, StreamingContext) |
Elavult.
Inicializálja az TimeoutException osztály új példányát szerializált adatokkal. |
| TimeoutException(String, Exception) |
Inicializálja az TimeoutException osztály új példányát a megadott hibaüzenettel és belső kivétellel. |
| TimeoutException(String) |
Inicializálja az osztály új példányát TimeoutException a megadott hibaüzenettel. |
Tulajdonságok
| Name | Description |
|---|---|
| Data |
Lekéri a kulcs-/érték párok gyűjteményét, amelyek további, felhasználó által definiált információkat biztosítanak a kivételről. (Öröklődés forrása Exception) |
| HelpLink |
Lekéri vagy beállítja a kivételhez társított súgófájlra mutató hivatkozást. (Öröklődés forrása Exception) |
| HResult |
Lekéri vagy beállítja a HRESULT-ot, egy kódolt numerikus értéket, amely egy adott kivételhez van hozzárendelve. (Öröklődés forrása Exception) |
| InnerException |
Lekéri az Exception aktuális kivételt okozó példányt. (Öröklődés forrása Exception) |
| Message |
Az aktuális kivételt leíró üzenet jelenik meg. (Öröklődés forrása Exception) |
| Source |
Lekéri vagy beállítja az alkalmazás vagy a hibát okozó objektum nevét. (Öröklődés forrása Exception) |
| StackTrace |
Lekéri a hívásverem közvetlen kereteinek sztringképét. (Öröklődés forrása Exception) |
| TargetSite |
Lekéri az aktuális kivételt okozó metódust. (Öröklődés forrása Exception) |
Metódusok
| Name | Description |
|---|---|
| Equals(Object) |
Meghatározza, hogy a megadott objektum egyenlő-e az aktuális objektummal. (Öröklődés forrása Object) |
| GetBaseException() |
Ha egy származtatott osztály felül van bírálva, egy Exception vagy több későbbi kivétel kiváltó okát adja vissza. (Öröklődés forrása Exception) |
| GetHashCode() |
Ez az alapértelmezett kivonatoló függvény. (Öröklődés forrása Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Elavult.
Ha felül van bírálva egy származtatott osztályban, a SerializationInfo kivétel adatait adja meg. (Öröklődés forrása Exception) |
| GetType() |
Lekéri az aktuális példány futtatókörnyezeti típusát. (Öröklődés forrása Exception) |
| MemberwiseClone() |
Az aktuális Objectpéldány sekély másolatát hozza létre. (Öröklődés forrása Object) |
| ToString() |
Létrehozza és visszaadja az aktuális kivétel sztring-ábrázolását. (Öröklődés forrása Exception) |
esemény
| Name | Description |
|---|---|
| SerializeObjectState |
Elavult.
Akkor fordul elő, ha a kivétel szerializálva van egy kivételállapot-objektum létrehozásához, amely szerializált adatokat tartalmaz a kivételről. (Öröklődés forrása Exception) |