From 25e217e330732c98b4d533534dbee12282a508a9 Mon Sep 17 00:00:00 2001 From: softwarepronto Date: Mon, 24 Oct 2022 01:57:40 -0700 Subject: [PATCH 1/3] Fx handler methods for event UploadProgressChanged The documentation for WebClient.UploadProgressChanged event is as follows: https://learn.microsoft.com/en-us/dotnet/api/system.net.webclient.uploadprogresschanged?view=net-6.0 This documentation for UploadProgressChanged uses that originally included: client.UploadFileCompleted += new UploadFileCompletedEventHandler(UploadFileCallback2); client.UploadProgressChanged += new UploadProgressChangedEventHandler(UploadProgressCallback); The documentation page for UploadProgressChanged then contains a reference to Snippet42 to document the above methods but Snippet42 contains the following methods: UploadProgressCallback DownloadProgressCallback: this is a download method not used in Snippet3 Snippet4 contains the documentation needed by Snippet3 -- the definition of the UploadFileCallback2 method. Snippet4 has no UploadProgressChangedEventHandler. I made a copy of the original UploadProgressCallback and called it UploadProgressCallback2. I placed this in Snippet4 and updated Snippet3 to reference UploadProgressCallback2 instead of UploadProgressCallback. Once asyncmethods.cs is updated, I will change the source to this link: https://learn.microsoft.com/en-us/dotnet/api/system.net.webclient.uploadprogresschanged?view=net-6.0 I will swap out the reference to Snippet42 and replace it with Snippet4. I am pretty sure Snippet41 and Snippet42 are orphaned but this is obsolete documentation. I'd rather fix what is obviously broken (Snippet4) than purge unused code. --- .../Overview/asyncmethods.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/snippets/csharp/System.Net/DownloadDataCompletedEventArgs/Overview/asyncmethods.cs b/snippets/csharp/System.Net/DownloadDataCompletedEventArgs/Overview/asyncmethods.cs index ba2d0021bc3..9cbe0d8a36e 100644 --- a/snippets/csharp/System.Net/DownloadDataCompletedEventArgs/Overview/asyncmethods.cs +++ b/snippets/csharp/System.Net/DownloadDataCompletedEventArgs/Overview/asyncmethods.cs @@ -60,7 +60,7 @@ public static void UploadFileInBackground2(string address, string fileName) client.UploadFileCompleted += new UploadFileCompletedEventHandler(UploadFileCallback2); // Specify a progress notification handler. - client.UploadProgressChanged += new UploadProgressChangedEventHandler(UploadProgressCallback); + client.UploadProgressChanged += new UploadProgressChangedEventHandler(UploadProgressCallback2); client.UploadFileAsync(uri, "POST", fileName); Console.WriteLine("File upload started."); } @@ -72,6 +72,16 @@ private static void UploadFileCallback2(Object sender, UploadFileCompletedEventA string reply = System.Text.Encoding.UTF8.GetString(e.Result); Console.WriteLine(reply); } + + private static void UploadProgressCallback2(object sender, UploadProgressChangedEventArgs e) + { + // Displays the operation identifier, and the transfer progress. + Console.WriteLine("{0} uploaded {1} of {2} bytes. {3} % complete...", + (string)e.UserState, + e.BytesSent, + e.TotalBytesToSend, + e.ProgressPercentage); + } // // From 54634de767920c5648f7ff352fe48b8678d72f8f Mon Sep 17 00:00:00 2001 From: softwarepronto Date: Mon, 24 Oct 2022 11:21:33 -0700 Subject: [PATCH 2/3] UploadProgressChanged created correct snippet44 The documentation for UploadProgressChanged is incorrectly using snippet42. Snippet44 represents the method subscribed to the events in the UploadProgressChanged documentation. --- .../DownloadDataCompletedEventArgs/Overview/asyncmethods.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/snippets/csharp/System.Net/DownloadDataCompletedEventArgs/Overview/asyncmethods.cs b/snippets/csharp/System.Net/DownloadDataCompletedEventArgs/Overview/asyncmethods.cs index 9cbe0d8a36e..93e1255d717 100644 --- a/snippets/csharp/System.Net/DownloadDataCompletedEventArgs/Overview/asyncmethods.cs +++ b/snippets/csharp/System.Net/DownloadDataCompletedEventArgs/Overview/asyncmethods.cs @@ -66,12 +66,14 @@ public static void UploadFileInBackground2(string address, string fileName) } // + // // private static void UploadFileCallback2(Object sender, UploadFileCompletedEventArgs e) { string reply = System.Text.Encoding.UTF8.GetString(e.Result); Console.WriteLine(reply); } + // private static void UploadProgressCallback2(object sender, UploadProgressChangedEventArgs e) { @@ -82,7 +84,7 @@ private static void UploadProgressCallback2(object sender, UploadProgressChanged e.TotalBytesToSend, e.ProgressPercentage); } - // + // // // Sample call: UploadFileInBackground("http://www.contoso.com/fileUpload.aspx", "data.txt") From ce0c7a6d5b5c2fc4429e781c9814c332ecec4972 Mon Sep 17 00:00:00 2001 From: softwarepronto Date: Mon, 24 Oct 2022 11:32:12 -0700 Subject: [PATCH 3/3] Fixed code snippet UploadProgressChanged C# only fix -- Snippet4 was related in the documentation to Snippt42. The methods used in Snippet4 did not match Snippet42. Snippet44 was created so that it shows the methods subscribed to the events by Snippet4. --- xml/System.Net/WebClient.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml/System.Net/WebClient.xml b/xml/System.Net/WebClient.xml index 36d6b64a19f..2c3f351a0d0 100644 --- a/xml/System.Net/WebClient.xml +++ b/xml/System.Net/WebClient.xml @@ -7163,7 +7163,7 @@ internal class MyWebClient : WebClientProtocol The following code example shows an implementation of a handler for this event. [!code-cpp[NCLWebClientAsync#42](~/snippets/cpp/VS_Snippets_Remoting/NCLWebClientAsync/CPP/asyncmethods.cpp#42)] - [!code-csharp[NCLWebClientAsync#42](~/snippets/csharp/System.Net/DownloadDataCompletedEventArgs/Overview/asyncmethods.cs#42)] + [!code-csharp[NCLWebClientAsync#44](~/snippets/csharp/System.Net/DownloadDataCompletedEventArgs/Overview/asyncmethods.cs#44)] [!code-vb[NCLWebClientAsync#42](~/snippets/visualbasic/VS_Snippets_Remoting/NCLWebClientAsync/VB/asyncmethods.vb#42)] ]]>