From e965b1379c972686846f7b9c314a9cd5174cbb88 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Thu, 9 Jan 2025 14:18:45 +0100 Subject: [PATCH 1/3] File.OpenWrite doc improvements (#10822) * remove redundant comments from the snippet * fix the description --------- Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --- .../System.IO/FileInfo/OpenWrite/file openwrite.cs | 13 ------------- xml/System.IO/FileInfo.xml | 2 +- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/snippets/csharp/System.IO/FileInfo/OpenWrite/file openwrite.cs b/snippets/csharp/System.IO/FileInfo/OpenWrite/file openwrite.cs index 7b0e20ae25e..d6ad07013f8 100644 --- a/snippets/csharp/System.IO/FileInfo/OpenWrite/file openwrite.cs +++ b/snippets/csharp/System.IO/FileInfo/OpenWrite/file openwrite.cs @@ -34,18 +34,5 @@ public static void Main() } } //This code produces output similar to the following; -//results may vary based on the computer/file structure/etc.: -// //This is to test the OpenWrite method. -// -// -// -// -// -// -// -// -// -// -// // diff --git a/xml/System.IO/FileInfo.xml b/xml/System.IO/FileInfo.xml index 3526f7193ab..f6445bfdf6c 100644 --- a/xml/System.IO/FileInfo.xml +++ b/xml/System.IO/FileInfo.xml @@ -2137,7 +2137,7 @@ The following example demonstrates moving a file to a different location and ren method opens a file if one already exists for the file path, or creates a new file if one does not exist. For an existing file, it does not append the new text to the existing text. Instead, it overwrites the existing characters with the new characters. If you overwrite a longer string (such as "This is a test of the OpenWrite method") with a shorter string (like "Second run"), the file will contain a mix of the strings ("Second runtest of the OpenWrite method"). + The method opens a file if one already exists for the file path, or creates a new file if one does not exist. For an existing file, it does not append the new text to the existing text. Instead, it overwrites the existing characters with the new characters. If you overwrite a longer string (such as "This is a test of the OpenWrite method") with a shorter string (like "Second run"), the file will contain a mix of the strings ("Second run test of the OpenWrite method."). From 127cf347e6de5e0c10cf1a75c74be59fbebccacf Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 9 Jan 2025 07:56:12 -0800 Subject: [PATCH 2/3] Remove Xamarin reference (#10748) --- xml/System.Net.Mail/SmtpClient.xml | 55 +++++++++++++----------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/xml/System.Net.Mail/SmtpClient.xml b/xml/System.Net.Mail/SmtpClient.xml index 11e440cfd6b..02b5d854808 100644 --- a/xml/System.Net.Mail/SmtpClient.xml +++ b/xml/System.Net.Mail/SmtpClient.xml @@ -58,51 +58,45 @@ - Allows applications to send email by using the Simple Mail Transfer Protocol (SMTP). The type is obsolete on some platforms and not recommended on others; for more information, see the Remarks section. + Sends email by using the Simple Mail Transfer Protocol (SMTP). The type is not recommended for new development; for more information, see the Remarks section. - [!IMPORTANT] -> We don't recommend that you use the `SmtpClient` class for new development because `SmtpClient` doesn't support many modern protocols. Use [MailKit](https://github.com/jstedfast/MailKit) or other libraries instead. For more information, see [SmtpClient shouldn't be used](https://github.com/dotnet/platform-compat/blob/master/docs/DE0005.md) on GitHub. +> We don't recommend that you use the `SmtpClient` class for new development because `SmtpClient` doesn't support many modern protocols. Use [MailKit](https://github.com/jstedfast/MailKit) or other libraries instead. For more information, see [SmtpClient shouldn't be used](https://github.com/dotnet/platform-compat/blob/master/docs/DE0005.md). -The `SmtpClient` class is obsolete in Xamarin. However: +The `SmtpClient` class is: -- It is included in the .NET Standard 2.0 and later versions and therefore must be part of any .NET implementation that supports those versions. -- It is present and can be used in .NET Framework 4 through .NET Framework 4.8. -- It is usable in .NET Core, but its use isn't recommended. +- Included in .NET Standard 2.0 and later versions and therefore must be part of any .NET implementation that supports those versions. +- Present and can be used in .NET Framework 4 through .NET Framework 4.8. +- Usable in .NET (Core), but its use isn't recommended. The classes shown in the following table are used to construct email messages that can be sent using . -|Class|Description| -|-----------|-----------------| -||Represents file attachments. This class allows you to attach files, streams, or text to an email message.| -||Represents the email address of the sender and recipients.| -||Represents an email message.| +| Class | Description | +|------------------------------------|------------------------------------------------------------| +| | Represents file attachments. This class allows you to attach files, streams, or text to an email message. | +| | Represents the email address of the sender and recipients. | +| | Represents an email message. | To construct and send an email message by using , you must specify the following information: -- The SMTP host server that you use to send email. See the and properties. - -- Credentials for authentication, if required by the SMTP server. See the property. - -- The email address of the sender. See the and methods that take a `from` parameter. Also see the property. - -- The email address or addresses of the recipients. See the and methods that take a `recipient` parameter. Also see the property. - -- The message content. See the and methods that take a `body` parameter. Also see the property. - - To include an attachment with an email message, first create the attachment by using the class, and then add it to the message by using the property. Depending on the email reader used by the recipients and the file type of the attachment, some recipients might not be able to read the attachment. For clients that cannot display the attachment in its original form, you can specify alternate views by using the property. +- The SMTP host server that you use to send email. See the and properties. +- Credentials for authentication, if required by the SMTP server. See the property. +- The email address of the sender. See the and methods that take a `from` parameter. Also see the property. +- The email address or addresses of the recipients. See the and methods that take a `recipient` parameter. Also see the property. +- The message content. See the and methods that take a `body` parameter. Also see the property. + +To include an attachment with an email message, first create the attachment by using the class, and then add it to the message by using the property. Depending on the email reader used by the recipients and the file type of the attachment, some recipients might not be able to read the attachment. For clients that cannot display the attachment in its original form, you can specify alternate views by using the property. In .NET Framework, you can use the application or machine configuration files to specify default host, port, and credentials values for all objects. For more information, see [<mailSettings> Element (Network Settings)](/dotnet/framework/configure-apps/file-schema/network/mailsettings-element-network-settings). .NET Core does not support setting defaults. As a workaround, you must set the relevant properties on directly. To send the email message and block while waiting for the email to be transmitted to the SMTP server, use one of the synchronous methods. To allow your program's main thread to continue executing while the email is transmitted, use one of the asynchronous methods. The event is raised when a operation completes. To receive this event, you must add a delegate to . The delegate must reference a callback method that handles notification of events. To cancel an asynchronous email transmission, use the method. > [!NOTE] -> If there is an email transmission in progress and you call or again, you will receive an . +> If there is an email transmission in progress and you call or again, you will receive an . The connection established by the current instance of the class to the SMTP server may be re-used if an application wishes to send multiple messages to the same SMTP server. This is particularly useful when authentication or encryption are used establish a connection to the SMTP server. The process of authenticating and establishing a TLS session can be expensive operations. A requirement to re-establish a connection for each message when sending a large quantity of email to the same SMTP server could have a significant impact on performance. There are a number of high-volume email applications that send email status updates, newsletter distributions, or email alerts. Also many email client applications support an off-line mode where users can compose many email messages that are sent later when a connection to the SMTP server is established. It is typical for an email client to send all SMTP messages to a specific SMTP server (provided by the Internet service provider) that then forwards this email to other SMTP servers. @@ -112,12 +106,11 @@ The classes shown in the following table are used to construct email messages th The class has no `Finalize` method, so an application must call to explicitly free up resources. The method iterates through all established connections to the SMTP server specified in the property and sends a QUIT message followed by gracefully ending the TCP connection. The method also releases the unmanaged resources used by the and optionally disposes of the managed resources. - Call when you are finished using the . The method leaves the in an unusable state. After calling , you must release all references to the so the garbage collector can reclaim the memory that the was occupying. - - - + Call when you are finished using the . The method leaves the in an unusable state. After calling , you must release all references to the so the garbage collector can reclaim the memory that the was occupying. + ## Examples - The following code example demonstrates sending an email message asynchronously. + +The following code example demonstrates sending an email message asynchronously. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/NclMailASync/cpp/mailasync.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Net.Mail/MailAddress/.ctor/mailasync.cs" id="Snippet1"::: From 3cfcb5c572eef5a4e00e3c9f03cc79bce6c4455b Mon Sep 17 00:00:00 2001 From: Maoni Stephens Date: Thu, 9 Jan 2025 13:00:01 -0800 Subject: [PATCH 3/3] Fix for Add/RemoveMemoryPressure doc (#10823) --- xml/System/GC.xml | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/xml/System/GC.xml b/xml/System/GC.xml index a20a3afbba8..2e66ec4d671 100644 --- a/xml/System/GC.xml +++ b/xml/System/GC.xml @@ -126,13 +126,9 @@ The following example uses several GC methods to get generation and memory infor method informs the runtime of this additional pressure on system memory. + The common pattern for releasing native resources is via a type's finalizer. If a managed object uses native memory, it can free that native memory in its finalizer. The garbage collector only knows about managed memory and schedules collections based on this knowledge. Imagine a scenario where a small managed object is associated with a large amount of native memory usage, and this managed object now lives in gen2. A gen2 GC might not happen for some time, which means the large amount of native memory won't be released until the next gen2 happens. The runtime provides the and methods to help with this scenario. The runtime keeps an internal record of how much memory pressure these APIs added and removed, and triggers a gen2 GC if deemed productive. So this is not a feature of the GC but rather something that the runtime provides to trigger GCs. - The and methods improve performance only for types that exclusively depend on finalizers to release the unmanaged resources. It's not necessary to use these methods in types that follow the dispose pattern, where finalizers are used to clean up unmanaged resources only in the event that a consumer of the type forgets to call `Dispose`. For more information on object finalization and the dispose pattern, see [Cleaning Up Unmanaged Resources](/dotnet/standard/garbage-collection/unmanaged). - - In the simplest usage pattern, a managed object allocates unmanaged memory in the constructor and releases it in the `Finalize` method. Call the method after allocating the unmanaged memory, and call the method after releasing it. - - In more complicated scenarios, where the unmanaged memory allocation changes substantially during the lifetime of the managed object, you can call the and methods to communicate these incremental changes to the runtime. + If you have a convenient place to call these APIs, you don't necessarily have to use a finalizer. For example, if you know you can release the native memory when a specific method on the type is called, you can call the method at that point instead of having a finalizer. > [!CAUTION] > You must ensure that you remove exactly the amount of pressure you add. Failing to do so can adversely affect the performance of the system in applications that run for long periods of time. @@ -1701,13 +1697,9 @@ The following example demonstrates the use of the method informs the runtime of this additional pressure on system memory, and the method informs the runtime that the additional pressure has been released. - - The and methods improve performance only for types that exclusively depend on finalizers to release the unmanaged resources. It's not necessary to use these methods in types that follow the dispose pattern, where finalizers are used to clean up unmanaged resources only in the event that a consumer of the type forgets to call `Dispose`. For more information on object finalization and the dispose pattern, see [Cleaning Up Unmanaged Resources](/dotnet/standard/garbage-collection/unmanaged). - - In the simplest usage pattern, a managed object allocates unmanaged memory in the constructor and releases it in the `Finalize` method. Call the method after allocating the unmanaged memory, and call the method after releasing it. + The common pattern for releasing native resources is via a type's finalizer. If a managed object uses native memory, it can free that native memory in its finalizer. The garbage collector only knows about managed memory and schedules collections based on this knowledge. Imagine a scenario where a small managed object is associated with a large amount of native memory usage, and this managed object now lives in gen2. A gen2 GC might not happen for some time, which means the large amount of native memory won't be released until the next gen2 happens. The runtime provides the and methods to help with this scenario. The runtime keeps an internal record of how much memory pressure these APIs added and removed, and triggers a gen2 GC if deemed productive. So this is not a feature of the GC but rather something that the runtime provides to trigger GCs. - In more complicated scenarios, where the unmanaged memory allocation changes substantially during the lifetime of the managed object, you can call the and methods to communicate these incremental changes to the runtime. + If you have a convenient place to call these APIs, you don't necessarily have to use a finalizer. For example, if you know you can release the native memory when a specific method on the type is called, you can call the method at that point instead of having a finalizer. > [!CAUTION] > You must ensure that you remove exactly the amount of pressure you add. Failing to do so can adversely affect the performance of the system in applications that run for long periods of time.