/// <summary> /// Opens the specified URI. /// </summary> /// <param name="uri">The URI.</param> /// <returns></returns> public async Task Open(Uri uri) { lock (SyncLock) { Commands.Clear(); } var command = new OpenCommand(this, uri); await command.ExecuteAsync(); }
/// <summary> /// Opens the specified URI. /// This command gets processed in a threadpool thread asynchronously. /// </summary> /// <param name="uri">The URI.</param> /// <returns>The asynchronous task</returns> public async Task OpenAsync(Uri uri) { // Check Uri Argument if (uri == null) { MediaElement?.Logger.Log( MediaLogMessageType.Warning, $"{nameof(MediaCommandManager)}.{nameof(OpenAsync)}: '{nameof(uri)}' cannot be null"); return; // Task.CompletedTask; } if (CanExecuteCommands == false) { return; // Task.CompletedTask; } else { IsOpening.Value = true; } var command = new OpenCommand(this, uri); ExecutingCommand = command; ClearCommandQueue(); var action = new Action(() => { try { if (command.HasCompleted) { return; } command.ExecuteAsync().GetAwaiter().GetResult(); } catch (Exception ex) { MediaElement?.Logger.Log( MediaLogMessageType.Error, $"{nameof(MediaCommandManager)}.{nameof(OpenAsync)}: {ex.GetType()} - {ex.Message}"); } finally { ExecutingCommand?.Complete(); ExecutingCommand = null; IsOpening.Value = false; } }); await Task.Run(action); }
/// <summary> /// Opens the specified URI. /// The command is processed in a Thread Pool Thread. /// </summary> /// <param name="uri">The URI.</param> /// <returns>The awaitable task</returns> public async Task Open(Uri uri) { lock (SyncLock) { Commands.Clear(); } // Process the command in a background thread as opposed // to in the thread that it was called to prevent blocking. await Task.Run(async() => { var command = new OpenCommand(this, uri); await command.ExecuteAsync(); }); }