From 39bdb739e2da4e292513a0a0e483c495ab440c70 Mon Sep 17 00:00:00 2001
From: albert-du <52804499+albert-du@users.noreply.github.com>
Date: Fri, 25 Mar 2022 16:00:40 -0700
Subject: [PATCH] TimeoutException F# snippet
---
.../TimeoutException/Overview/fs.fsproj | 13 ++++++
.../System/TimeoutException/Overview/to.fs | 42 +++++++++++++++++++
xml/System/TimeoutException.xml | 1 +
3 files changed, 56 insertions(+)
create mode 100644 snippets/fsharp/System/TimeoutException/Overview/fs.fsproj
create mode 100644 snippets/fsharp/System/TimeoutException/Overview/to.fs
diff --git a/snippets/fsharp/System/TimeoutException/Overview/fs.fsproj b/snippets/fsharp/System/TimeoutException/Overview/fs.fsproj
new file mode 100644
index 00000000000..d7d27929a83
--- /dev/null
+++ b/snippets/fsharp/System/TimeoutException/Overview/fs.fsproj
@@ -0,0 +1,13 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/TimeoutException/Overview/to.fs b/snippets/fsharp/System/TimeoutException/Overview/to.fs
new file mode 100644
index 00000000000..9f2458e8ad5
--- /dev/null
+++ b/snippets/fsharp/System/TimeoutException/Overview/to.fs
@@ -0,0 +1,42 @@
+//
+// 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()
+*)
+//
\ No newline at end of file
diff --git a/xml/System/TimeoutException.xml b/xml/System/TimeoutException.xml
index 57850f8fa00..c911f59410d 100644
--- a/xml/System/TimeoutException.xml
+++ b/xml/System/TimeoutException.xml
@@ -75,6 +75,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/TimeoutException.class/cpp/to.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/TimeoutException/Overview/to.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/TimeoutException/Overview/to.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/TimeoutException.class/VB/to.vb" id="Snippet1":::
]]>