Skip to content

Fx handler methods for event UploadProgressChanged #8569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,31 @@ 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.");
}
//</Snippet4>

//<Snippet44>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the snippet should not include the UploadFileCallback2 method to be consistent with examples for other event handlers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UploadProgressChanged has two events subscribed.
UploadFileCompleted has two event subscribed.
UploadValuesCompleted has zero events subscribed. This is on my list to fix.

If we want to make it consistent
UploadProgressChanged should have one event (remove one)
UploadFileCompleted should have one event (remove one)
UploadValuesCompleted should have one event (add one)

Is this how we should handle these last three events?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can have multiple events subscribed to, IMO it does not have to show the definition of the other handlers. I.e. show only UploadFileCompleted handler definition in docs for UploadFileCompleted event, as in https://learn.microsoft.com/en-us/dotnet/api/system.net.webclient.uploadfilecompleted?view=net-6.0&branch=main

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@softwarepronto Do you plan to make any more changes here?

//<Snippet5>
private static void UploadFileCallback2(Object sender, UploadFileCompletedEventArgs e)
{
string reply = System.Text.Encoding.UTF8.GetString(e.Result);
Console.WriteLine(reply);
}
//</Snippet5>

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);
}
//</Snippet44>

//<Snippet6>
// Sample call: UploadFileInBackground("http://www.contoso.com/fileUpload.aspx", "data.txt")
Expand Down
2 changes: 1 addition & 1 deletion xml/System.Net/WebClient.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

]]></format>
Expand Down