DCTekSolutions.SafeInvoker 1.0.0

dotnet add package DCTekSolutions.SafeInvoker --version 1.0.0
                    
NuGet\Install-Package DCTekSolutions.SafeInvoker -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="DCTekSolutions.SafeInvoker" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DCTekSolutions.SafeInvoker" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DCTekSolutions.SafeInvoker" />
                    
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 DCTekSolutions.SafeInvoker --version 1.0.0
                    
#r "nuget: DCTekSolutions.SafeInvoker, 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.
#:package DCTekSolutions.SafeInvoker@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DCTekSolutions.SafeInvoker&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DCTekSolutions.SafeInvoker&version=1.0.0
                    
Install as a Cake Tool

SafeInvoker

SafeInvoker helps ensure your WPF and WinForms code interacts with UI elements safely and correctly.
It provides a Fody-powered method attribute and a clean extension API for thread-safe UI invocation.

Free to use for personal and commercial projects. This package is closed source.


Features

  • [WPF.SafeInvoke] attribute for automatic thread safety on WPF methods
  • [Forms.SafeInvoke] attribute for WinForms control methods
  • ✅ Extension methods for DispatcherObject.SafeInvoke(...) (WPF)
  • ✅ Extension methods for Control.SafeInvoke(...) (WinForms)
  • ✅ Prevents InvalidOperationException from unsafe UI thread access
  • ✅ Supports nested and re-entrant dispatcher or control thread invocation

🚀 Usage Examples

1. WPF – Auto-Safe Method Invocation via Attribute

public class MyViewModel : DispatcherObject
{
    [WPF.SafeInvoke]
    public void UpdateUI()
    {
        Console.WriteLine($"Running on UI thread: {Dispatcher.CheckAccess()}");
    }
}

2. WPF – Manual SafeInvoke with Lambda

myWindow.SafeInvoke(w =>
{
    w.Title = "Updated safely from any thread!";
});

3. WinForms – Auto-Safe Method Invocation via Attribute

public class MyForm : Form
{
    [Forms.SafeInvoke]
    public void UpdateLabel()
    {
        myLabel.Text = "Thread-safe update";
    }
}

4. WinForms – Manual SafeInvoke with Lambda

myLabel.SafeInvoke(lbl =>
{
    lbl.Text = "Safe call from any thread";
});

5. Invoke with Action Delegate (WPF or WinForms)

(() => myWindow.Close()).SafeInvokeOn(myWindow.Dispatcher); // WPF
(() => myForm.Close()).SafeInvokeOn(myForm); // WinForms

🔐 Why SafeInvoker?

  • Eliminates brittle dispatcher/control checks in your code
  • Boosts reliability when using background tasks or async events
  • Protects against subtle UI crashes from cross-thread access
  • Works well in MVVM ViewModels, Forms, and controls

📦 Supported Platforms

  • .NET Framework 4.8
  • .NET Framework 4.8.1
  • .NET 6+ (Windows only)

🧪 Works Great With

  • CycleKit – round-robin async queues
  • AutoYumYum – DI via attributes
  • TransactionAction – chained atomic operations
  • ✅ MVVM, BackgroundWorker, DispatcherTimer, Task.Run(...), event handlers

✍️ Installation

  1. Install Fody and MethodDecorator.Fody
  2. Add [assembly: Interceptor] to your AssemblyInfo.cs
  3. Add [WPF.SafeInvoke] or [Forms.SafeInvoke]~~~~ to your method

💼 License

SafeInvoker is proprietary but free to use in personal and commercial projects.
See LICENSE.md for details.


☕ Support Future Development

If you find SafeInvoker helpful, please consider supporting us:

Buy Me A Coffee

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

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 148 6/20/2025

- Initial release of SafeInvokeWPFAttribute
           - Extension methods for DispatcherObject.SafeInvoke
           - Designed for WPF and WinForms thread safety
           - Compatible with .NET Standard 2.0 and 2.1