/// <remarks> /// <p>Starts a <see cref="WindowsClipboardSession" /> in an async contexts.</p> /// <p>Sends the session to abstract <see cref="Exists" /> and <see cref="Read" /> methods.</p> /// </remarks> /// <inheritdoc /> /// <returns>Null if <see cref="Exists" /> method returns <c>FALSE</c>; otherwise result from <see cref="Read" /></returns> /// <seealso cref="Exists" /> /// <seealso cref="Read" /> /// <exception cref="ClipboardWindowsApiException">Connection to the clipboard could not be opened.</exception> /// <exception cref="ClipboardTimeoutException">Connection to clipboard fails after timeout</exception> public Task <TResult> ReadAsync() { return(TaskHelper.StartStaTask(() => { using var session = new WindowsClipboardSession(); var context = new ClipboardReadingContext(session); if (!Exists(context)) { return null; } EnsureOpenConnection(session); var result = Read(context); return result; })); }
/// <inheritdoc /> /// <exception cref="ClipboardWindowsApiException"> /// <p>Communication with windows API's has failed.</p> /// <p>Connection to the clipboard could not be opened</p> /// </exception> /// <exception cref="ClipboardTimeoutException">Connection to clipboard fails after timeout</exception> /// <exception cref="ArgumentNullException"><paramref name="data" /> is <see langword="null" /></exception> public Task <bool> WriteAsync(TData data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } return(TaskHelper.StartStaTask(() => { using var clipboard = new WindowsClipboardSession(); var context = new ClipboardWritingContext(clipboard); EnsureOpenConnection(clipboard); ClearClipboard(clipboard); var result = Write(context, data); ThrowIfNotSuccessful(result); return result.IsSuccessful; })); }