TimeoutException Třída

Definice

Výjimka, která je vyvolána, když vypršel čas přidělený pro proces nebo operaci vypršela.

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
Dědičnost
TimeoutException
Dědičnost
TimeoutException
Odvozené
Atributy

Příklady

Následující příklad kódu ukazuje použití TimeoutException ve spojení se členy System.IO.Ports.SerialPort třídy.

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

#using <System.dll>

using namespace System;
using namespace System::IO::Ports;

int main()
{
    String^ input;
    try
    {
        // Set the COM1 serial port to speed = 4800 baud, parity = odd,
        // data bits = 8, stop bits = 1.
        SerialPort^ port = gcnew SerialPort("COM1",
            4800, Parity::Odd, 8, StopBits::One);
        // Timeout after 2 seconds.
        port->ReadTimeout = 2000;
        port->Open();

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

        port->Close();

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

    // Only catch timeout exceptions.
    catch (TimeoutException^ ex)
    {
        Console::WriteLine(ex);
    }
};
/*
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.

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()
'

Poznámky

Informace o nastavení intervalu časového limitu před TimeoutException vyvolání výjimky najdete v dokumentaci k typu, jehož časový limit metody vypršel. Informace o zpracování časového limitu najdete v dokumentaci k metodě, která vyvolala výjimku.

TimeoutException používá HRESULT, COR_E_TIMEOUT, který má hodnotu 0x80131505.

Seznam počátečních hodnot vlastností pro instanci TimeoutExceptionnaleznete v TimeoutException konstruktorech.

Konstruktory

TimeoutException()

Inicializuje novou instanci TimeoutException třídy.

TimeoutException(SerializationInfo, StreamingContext)

Inicializuje novou instanci třídy TimeoutException se serializovanými daty.

TimeoutException(String)

Inicializuje novou instanci třídy se zadanou chybovou TimeoutException zprávou.

TimeoutException(String, Exception)

Inicializuje novou instanci třídy se zadanou chybovou TimeoutException zprávou a vnitřní výjimkou.

Vlastnosti

Data

Získá kolekci párů klíč/hodnota, které poskytují další uživatelem definované informace o výjimce.

(Zděděno od Exception)
HelpLink

Získá nebo nastaví odkaz na soubor nápovědy přidružený k této výjimce.

(Zděděno od Exception)
HResult

Získá nebo nastaví HRESULT, kódovanou číselnou hodnotu přiřazenou konkrétní výjimce.

(Zděděno od Exception)
InnerException

Exception Získá instanci, která způsobila aktuální výjimku.

(Zděděno od Exception)
Message

Získá zprávu, která popisuje aktuální výjimku.

(Zděděno od Exception)
Source

Získá nebo nastaví název aplikace nebo objektu, který způsobuje chybu.

(Zděděno od Exception)
StackTrace

Získá řetězcové znázornění okamžitých rámců v zásobníku volání.

(Zděděno od Exception)
TargetSite

Získá metodu, která vyvolá aktuální výjimku.

(Zděděno od Exception)

Metody

Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

(Zděděno od Object)
GetBaseException()

Při přepsání v odvozené třídě vrátí Exception hodnotu, která je hlavní příčinou jedné nebo více následných výjimek.

(Zděděno od Exception)
GetHashCode()

Slouží jako výchozí funkce hash.

(Zděděno od Object)
GetObjectData(SerializationInfo, StreamingContext)

Při přepsání v odvozené třídě nastaví s SerializationInfo informacemi o výjimce.

(Zděděno od Exception)
GetType()

Získá typ modulu runtime aktuální instance.

(Zděděno od Exception)
MemberwiseClone()

Vytvoří použádnou kopii aktuálního souboru Object.

(Zděděno od Object)
ToString()

Vytvoří a vrátí řetězcovou reprezentaci aktuální výjimky.

(Zděděno od Exception)

událost

SerializeObjectState
Zastaralé.

Nastane, když je výjimka serializována k vytvoření objektu stavu výjimky, který obsahuje serializovaná data o výjimce.

(Zděděno od Exception)

Platí pro

Viz také