unosquare / ffmediaelement

FFME: The Advanced WPF MediaElement (based on FFmpeg)
https://unosquare.github.io/ffmediaelement/
Other
1.17k stars 240 forks source link

ConfiguredTaskAwaitable shall not be used #507

Closed MrRickwi closed 3 years ago

MrRickwi commented 4 years ago

ConfiguredTaskAwaitable shall not be used

ConfiguredTaskAwaitable is a struct that is only meant for use by the compiler. It should be replaced by clean async/await pattern using async Task instead.

Issue Categories

mariodivece commented 4 years ago

Hello @MrRickwi could you point me to the right documentation where I can learn about this a little more?

MrRickwi commented 4 years ago

If you look in Microsoft code reference, you will find the following comment:

/// <summary>Provides an awaitable object that allows for configured awaits on <see cref="System.Threading.Tasks.Task"/>.</summary> /// <remarks>This type is intended for compiler use only.</remarks> public struct ConfiguredTaskAwaitable {

This shows you that the struct should not be used.

Generally, use async Task<T> as result instead of ConfiguredTaskAwaitable<T>, and use ConfigureAwait(false) instead of ConfigureAwait(true), see here.

Most of the methods in MediaElement which return ConfiguredTaskAwaitable due to the ConfigureAwait should be rewritten like this:

public async Task<bool> ChangeMedia() { try { return await MediaCore.ChangeMedia().ConfigureAwait(false); } catch (Exception ex) { PostMediaFailedEvent(ex); } return false; }

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.