-
Notifications
You must be signed in to change notification settings - Fork 982
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
Avoid using LoadAsync() method of PictureBox control #242
Comments
The |
@ericstj , could you take a look? |
In addition: What do folks think about making this method |
It doesn't promise returning a Task, that's some naming convention which was invented way later than WinForms. Errors are reported through LoadCompleted event, would you obsolete that as well or expose the same error twice through different means? Without having a proper infrastructure for async support in the WinForms framework I see little value in adding Task support for this particular method. How would existing callers be migrated to await the Task? Existing callers are most likely not in an async method so awaiting for purpose of observing potential errors is trouble most callers probably discard (and then get killed by unhandled exceptions if an error actually happens and they didn't observe it, I see that kind of lazy programming crashes constantly in UWP apps where async is forced onto the UI and people ignore error handling because the framework provides no easy way to do it correctly). Alltogether, I agree WinForms needs to think about async support, but this is probably not a good place to start with. |
I think we just have! 😊 Think about the target audience for a second that WinForms has - this is quite different from what you normally have in Core. So, I think, this might be even a great opportunity to start, because the use case is simple and straight forward. On top I expect the actual usage of this method extremely low. And at the same time, I expect that the typical Windows audience expects the usage of this method extremely differently: If a Dev sees this method ending with Async, they will be rather surprised not getting back a So, obviously it's not my intension to break existing apps. What's in is in and no one wants to take that out. But I don't see any reason to tag both methods with |
البرمجة بالعربية غير مدعومة Automated translation: Programming in Arabic is not supported |
@asmaaswt we use English in our repos - we not have capability and/or capacity to use other languages. English is treated as most common language for most developers world-wide. I used automated translation (updated above), but I am not sure if it is correct, or how it relates to this specific issue. Can you please explain in more details what you meant and how it relates to this issue? Thanks! |
I gave it a try, to my surprise |
Just to confirm, I believe this is intentional per winforms/src/System.Windows.Forms/src/System/Windows/Forms/PictureBox.cs Lines 671 to 674 in 408a31d
Alternatively just use the Task infrastructure to run the code on a background thread.
We had similar goals back in .NETCore1.0 but dialed it back. In most cases it's not worth breaking someone over just having a newer API. There should be some really good reason to force a dev to think about the change. "New" is not a good enough reason. Thus we still have all the old event-based and APM based API next to task based API. It's a reasonable goal to plumb task-based async API through WinForms, but that should be done in a wave impacting all async winforms APIs. That way you aren't forcing people to learn two different async programming models. I can imagine that being a pretty huge task given that WinForms relies heavily on the event-based model. |
Closing per @ericstj comment above. This is by design. |
@merriemcgaw The runtime behavior is by design, but there should be a fix made in WinForms to compensate for it. https://devblogs.microsoft.com/dotnet/migrating-delegate-begininvoke-calls-for-net-core/ has detailed guidance on what to change BeginInvoke to. |
This has been fixed and the release will be coming soon. dotnet/platform-compat#130 (comment) |
Async delegates have been deprecated in .NET Core (see https://github.com/dotnet/corefx/issues/5940) for reasons such as: * Async delegates use deprecated IAsyncResult-based async pattern. This pattern is generally not supported throughout .NET Core base libraries. * Async delegates depend on remoting (System.Runtime.Remoting) under the hood. Remoting is not supported in .NET Core. For more detailed reasons and migration strategies please refer to https://devblogs.microsoft.com/dotnet/migrating-delegate-begininvoke-calls-for-net-core/ In case of WinForms, async pattern predates the Task-based Asynchronous Pattern and it does not return awaitables. In order to minimise the change to the public API surface we continue to expose the existing API and just re-route the image loading routine to a `Task` runner under the covers. Fixes dotnet#242 Fixes dotnet#1548
Verified this bug with .Net core 3.0.100-rc1-014190 from release branch, the issue has been fixed. |
Steps to reproduce:
Expected Result:
LoadAsync
should be executed. (NOTE: AlthoughLoadAsync
implies this, the method does not returnTask
butvoid
, so the usage here is correct with regards toasync
/await.
)Actual Result: An exception pops up, please see following screenshot and exception log.
Exception log:
The text was updated successfully, but these errors were encountered: