DCTekSolutions.SafeInvoker
1.0.0
dotnet add package DCTekSolutions.SafeInvoker --version 1.0.0
NuGet\Install-Package DCTekSolutions.SafeInvoker -Version 1.0.0
<PackageReference Include="DCTekSolutions.SafeInvoker" Version="1.0.0" />
<PackageVersion Include="DCTekSolutions.SafeInvoker" Version="1.0.0" />
<PackageReference Include="DCTekSolutions.SafeInvoker" />
paket add DCTekSolutions.SafeInvoker --version 1.0.0
#r "nuget: DCTekSolutions.SafeInvoker, 1.0.0"
#:package DCTekSolutions.SafeInvoker@1.0.0
#addin nuget:?package=DCTekSolutions.SafeInvoker&version=1.0.0
#tool nuget:?package=DCTekSolutions.SafeInvoker&version=1.0.0
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
- Install Fody and MethodDecorator.Fody
- Add
[assembly: Interceptor]
to yourAssemblyInfo.cs
- 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:
Product | Versions 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. |
-
.NETFramework 4.8
- MethodBoundaryAspect.Fody (>= 2.0.149)
- MethodDecorator.Fody (>= 1.1.1)
-
.NETFramework 4.8.1
- MethodBoundaryAspect.Fody (>= 2.0.149)
- MethodDecorator.Fody (>= 1.1.1)
-
net6.0-windows7.0
- MethodBoundaryAspect.Fody (>= 2.0.149)
- MethodDecorator.Fody (>= 1.1.1)
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