Avoid using LoadAsync() method of PictureBox control
See original GitHub issueSteps to reproduce:
- Create a new WinForms Core App.
- Add the following Code to the Form’s constructor.
public Form1()
{
InitializeComponent();
System.Windows.Forms.PictureBox pb = new PictureBox();
pb.ImageLocation = @"\\winformssrvvm01\BAQAFiles\v-mikou\OGF Doc\picture\myLargeImage1.bmp";
pb.LoadAsync();
}
- Run the app.
Expected Result: LoadAsync should be executed. (NOTE: Although LoadAsync implies this, the method does not return Task but void, so the usage here is correct with regards to async/await.)
Actual Result: An exception pops up, please see following screenshot and exception log.

Exception log:
System.PlatformNotSupportedException
HResult=0x80131539
Message=Operation is not supported on this platform.
Source=System.Private.CoreLib
StackTrace:
at System.Threading.WaitCallback.BeginInvoke(Object state, AsyncCallback callback, Object object)
at System.Windows.Forms.PictureBox.LoadAsync()
at XpictureIssue.Form1..ctor() in C:\Users\v-zheshi\source\winforms\XpictureIssue\Form1.cs:line 20
at XpictureIssue.Program.Main() in C:\Users\v-zheshi\source\winforms\XpictureIssue\Program.cs:line 19
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (12 by maintainers)
Top Results From Across the Web
Asynchronously Load an Image from a Url to a PictureBox
PictireBox control supports loading images asynchronously itself and you don't need to use background worker or async/await. It also loads image ...
Read more >PictureBox.LoadAsync Method (System.Windows.Forms)
A call to the LoadAsync method sets the ImageLocation property to the value of url . Besides calling the LoadAsync method, you must...
Read more >Picturebox LoadAsync problem - vbCity - The .NET Developer ...
Basically, just create a blank project (which will contain form1), and add another form to the project named form2. In form1, add a...
Read more >PictureBox doesn't work as expected
Hello! I am trying to create an application that displays random images from Reddit every X seconds in new Form.
Read more >PictureBox load time notification
Within the LoadProgressChanged event you could call PictureBox.CancelAsync() to terminate the loading process, if necessary. Note: I have not ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Just to confirm, I believe this is intentional per https://github.com/dotnet/corefx/issues/5940#issuecomment-182107557 /cc @jkotas. You’ll need to make a fix to WinForms here to avoid this API. The comment here may not even apply any more on Core so perhaps you can just call BeginGetResponse https://github.com/dotnet/winforms/blob/408a31db5c58be99eff71ed94dfae6fda49364e0/src/System.Windows.Forms/src/System/Windows/Forms/PictureBox.cs#L671-L674 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.
In addition: What do folks think about making this method
Obsolete, and come up with a new one which does keep what its promising (namely returningTaskand notvoid)?