Oakrey.Async.Windows 1.0.0

dotnet add package Oakrey.Async.Windows --version 1.0.0
                    
NuGet\Install-Package Oakrey.Async.Windows -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Oakrey.Async.Windows" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Oakrey.Async.Windows" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Oakrey.Async.Windows" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Oakrey.Async.Windows --version 1.0.0
                    
#r "nuget: Oakrey.Async.Windows, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Oakrey.Async.Windows&version=1.0.0
                    
Install Oakrey.Async.Windows as a Cake Addin
#tool nuget:?package=Oakrey.Async.Windows&version=1.0.0
                    
Install Oakrey.Async.Windows as a Cake Tool

O.Async.Windows

Overview

The Async.Windows project is a specialized library designed to enhance asynchronous programming in WPF (Windows Presentation Foundation) applications. It provides utilities and abstractions to simplify working with asynchronous workflows, ensuring smooth integration with the WPF threading model and UI responsiveness. This library is particularly useful for developers building WPF applications that require efficient task management, UI thread synchronization, and event handling.

Features of Async.Windows

UI Task Management

Classes:

  • UiTask,
  • UiTask<T>,
  • UiTaskMethodBuilder,
  • UiTaskMethodBuilderGeneric<T>

Description:

  • These classes provide custom task implementations (UiTask and UiTask<T>) and method builders (UiTaskMethodBuilder and UiTaskMethodBuilderGeneric<T>) tailored for WPF applications.
  • They ensure that asynchronous operations are executed on the UI thread when necessary, leveraging the WPF Dispatcher.

Key Highlights:

  • Automatic context switching to the UI thread using Dispatcher.
  • Seamless integration with the async/await pattern.
  • Support for both non-generic and generic tasks.

Thread-Safe Invocation

Class: Invoker

Description:

  • Provides utility methods to safely invoke actions or functions on the WPF UI thread.

Key Highlights:

  • Invoke(Action action) and Invoke<T>(Func<T> func) for synchronous execution.
  • InvokeAsync(Action action) and InvokeAsync<T>(Func<T> func) for asynchronous execution.
  • Automatically checks and switches to the UI thread if the current thread does not have access.

Event Handling Utilities

Class: Events Description:

  • Contains helper methods for managing events and timers in WPF applications. Key Highlights:
  • UnsubscribeTimer: Safely unsubscribes and stops a DispatcherTimer.
  • WaitForEvent: Blocks the current thread until an event is signaled or a timeout occurs, using a DispatcherFrame to keep the UI responsive.

Dispatcher Integration

The library heavily relies on the WPF Dispatcher to ensure that all asynchronous operations and event handling are executed on the correct thread, maintaining UI thread safety.

Example Use Cases

  1. Asynchronous UI Updates: Use UiTask or UiTask<T> to perform background operations and update the UI seamlessly.
  2. Thread-Safe UI Invocation: Use Invoker.Invoke or Invoker.InvokeAsync to safely execute code on the UI thread from background threads.
  3. Timer Management: Use Events.UnsubscribeTimer to cleanly manage DispatcherTimer instances and avoid memory leaks.
  4. Event Waiting: Use Events.WaitForEvent to block execution until a specific event occurs, while keeping the UI responsive.

Installation

You can install the package via NuGet Package Manager, Package Manager Console or the .NET CLI.

NuGet Package Manager

  1. Open your project in Visual Studio.
  2. Navigate to Tools > NuGet Package Manager > Manage NuGet Packages for Solution....
  3. Search for Oakrey.Async.Windows and click Install.

.NET CLI

Run the following command in your terminal:

dotnet add package Oakrey.Async.Windows

Package Manager Console

Run the following command in your Package Manager Console:

Install-Package Oakrey.Async.Windows

Requirements

  • .NET 8 or higher

Project Information

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests to improve the package.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0-windows7.0 is compatible.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0-windows7.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Oakrey.Async.Windows:

Package Downloads
Oakrey.Applications.UI

A .NET library for building modern WPF user interfaces, featuring notifications, prompts, tabbed windows, and support for themes and animations

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 199 4/16/2025