AsyncClipboardService 1.7.1

Thread-safe, asynchronous windows clipboard service with retry strategy for .NET.

Install-Package AsyncClipboardService -Version 1.7.1
dotnet add package AsyncClipboardService --version 1.7.1
<PackageReference Include="AsyncClipboardService" Version="1.7.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AsyncClipboardService --version 1.7.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

AsyncWindowsClipboard

AsyncWindowsClipboard is thread-safe, asynchronous windows clipboard service with retry strategy for .NET

What it is

  • It gives async/await syntax to communicate with Windows clipboard API's.
  • It is thread safe.
  • It gives lower (binary) level read & write access to strings in clipboard than .NET implementation.
  • Implements retry strategies to connect to the clipboard when it's locked.

How it works

AsyncClipboardService ensures that:

  • The Tasks for the communication always run in the same thread which makes the communication thread safe.
  • The thread is in Single Thread Apartment (STA) model. WPF & Windows Forms uses COM interop to communicate with clipboard in STA state. Running the thread in same apartment state ensures that the library functions well. Read more at MSDN 1, 2, 3.
  • Implements retry strategy to ensure clipboard operation ends successfully.

How to use

Simple usage

You can use a new instance of WindowsClipboardService to retrieve data. It's okay to use the instance from different threads.

    var clipboardService = new WindowsClipboardService();
    await clipboardService.SetTextAsync("Hello world"); // Sets the text
    var data = await clipboardService.GetTextAsync(); // Reads "Hello world"

Recommended usage

However, it's recommended to use WindowsClipboardService with a timeout strategy, as it'll then wait (in a spinning state) for the thread that blocks the windows api instead of failing. You can activate the timeout strategy by setting it in the constructor:

    var clipboardService = new WindowsClipboardService(timeout:TimeSpan.FromMilliseconds(200)); 
    // or via its property
    var clipboardService = new ClipboardService { Timeout = TimeSpan.FromMilliseconds(200) };

AsyncWindowsClipboard

AsyncWindowsClipboard is thread-safe, asynchronous windows clipboard service with retry strategy for .NET

What it is

  • It gives async/await syntax to communicate with Windows clipboard API's.
  • It is thread safe.
  • It gives lower (binary) level read & write access to strings in clipboard than .NET implementation.
  • Implements retry strategies to connect to the clipboard when it's locked.

How it works

AsyncClipboardService ensures that:

  • The Tasks for the communication always run in the same thread which makes the communication thread safe.
  • The thread is in Single Thread Apartment (STA) model. WPF & Windows Forms uses COM interop to communicate with clipboard in STA state. Running the thread in same apartment state ensures that the library functions well. Read more at MSDN 1, 2, 3.
  • Implements retry strategy to ensure clipboard operation ends successfully.

How to use

Simple usage

You can use a new instance of WindowsClipboardService to retrieve data. It's okay to use the instance from different threads.

    var clipboardService = new WindowsClipboardService();
    await clipboardService.SetTextAsync("Hello world"); // Sets the text
    var data = await clipboardService.GetTextAsync(); // Reads "Hello world"

Recommended usage

However, it's recommended to use WindowsClipboardService with a timeout strategy, as it'll then wait (in a spinning state) for the thread that blocks the windows api instead of failing. You can activate the timeout strategy by setting it in the constructor:

    var clipboardService = new WindowsClipboardService(timeout:TimeSpan.FromMilliseconds(200)); 
    // or via its property
    var clipboardService = new ClipboardService { Timeout = TimeSpan.FromMilliseconds(200) };

Release Notes

- Exceptions are now properly serializable.
     - Fixed delay for retrying connection is being ignored.

  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.7.1 449 2/4/2020
1.7.0 173 1/1/2020
1.6.0 428 9/2/2018
1.5.0 1,027 10/6/2016
1.0.0.4 619 10/2/2016
1.0.0.3 636 9/30/2016
1.0.0.2 636 9/29/2016
1.0.0.1 792 9/28/2016
1.0.0 684 9/28/2016