TimeoutException クラス
アセンブリ: System.ServiceProcess (system.serviceprocess.dll 内)
構文
TimeoutException クラスでは、例外の原因を説明するメッセージを指定できます。通常、この例外がメソッドによってスローされる場合は、"指定したタイムアウトが経過したため、操作は完了しませんでした。" などのメッセージが表示されます。
たとえば、このクラスは、ServiceController クラスの WaitForStatus メンバによって使用されます。サービスの Status プロパティを Paused から ContinuePending に変更するなどの操作を行うと、この例外がスローされる可能性があります。
System.Exception
System.SystemException
System.ServiceProcess.TimeoutException
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
TimeoutException クラス
アセンブリ: mscorlib (mscorlib.dll 内)
構文
<SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public Class TimeoutException Inherits SystemException
[SerializableAttribute] [ComVisibleAttribute(true)] public ref class TimeoutException : public SystemException
TimeoutException は、値 0x80131505 を保持する HRESULT, COR_E_TIMEOUT を使用します。
TimeoutException のインスタンスの初期プロパティ値の一覧については、TimeoutException コンストラクタのトピックを参照してください。
System.IO.Ports.SerialPort クラスのメンバと組み合わせて TimeoutException を使用するコード例を次に示します。
' This example demonstrates the use of the TimeoutException ' exception in conjunction with the SerialPort class. Imports System 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 'Main End Class '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() '
// 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. #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. 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.Exception
System.SystemException
System.TimeoutException
プラットフォーム
Windows 98, Windows 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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- TimeoutException クラスのページへのリンク