forked from dotnet/winforms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:
PictureBox.LoadAsync
throws PlatformNotSupportedException
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
- Loading branch information
Showing
21 changed files
with
472 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/PictureBoxes.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/PictureBoxes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Data; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace WinformsControlsTest | ||
{ | ||
public partial class PictureBoxes : Form | ||
{ | ||
private const string Heading = "PictureBox tests"; | ||
private bool _isLoading; | ||
|
||
public PictureBoxes() | ||
{ | ||
InitializeComponent(); | ||
Text = Heading; | ||
} | ||
|
||
private void btnloadImage_Click(object sender, EventArgs e) | ||
{ | ||
if (string.IsNullOrWhiteSpace(imageUri.Text)) | ||
{ | ||
pictureBox1.Image = null; | ||
if (_isLoading) | ||
{ | ||
pictureBox1.CancelAsync(); | ||
} | ||
|
||
return; | ||
} | ||
|
||
try | ||
{ | ||
_isLoading = true; | ||
pictureBox1.WaitOnLoad = false; | ||
pictureBox1.LoadAsync(imageUri.Text); | ||
} | ||
catch (Exception ex) | ||
{ | ||
MessageBox.Show(ex.Message); | ||
} | ||
} | ||
|
||
private void pictureBox1_LoadCompleted(object sender, AsyncCompletedEventArgs e) | ||
{ | ||
_isLoading = false; | ||
Text = Heading; | ||
|
||
if (e.Cancelled) | ||
{ | ||
MessageBox.Show("Image loading cancelled"); | ||
} | ||
|
||
if (e.Error != null) | ||
{ | ||
MessageBox.Show(e.Error.Message, $"{e.Error.GetType().FullName} occurred"); | ||
} | ||
} | ||
|
||
private void pictureBox1_LoadProgressChanged(object sender, ProgressChangedEventArgs e) | ||
{ | ||
Text = $"{Heading}: loading image progress: {e.ProgressPercentage}%"; | ||
} | ||
} | ||
} |
Oops, something went wrong.