Making any call to a function of an object thread safe
I was wondering how to modify old code to support threads /task .
So I was making a small project about making any function of an object thread safe.
NuGet Package at : https://www.nuget.org/packages/ThreadSafeObject/
The solution contain tests and 2 console project for .NET Core and .NET Framework 4.5.1
The usage is pretty easy
Let’s say you have this
1 2 | Calculation c = new Calculation(); c.Add(); |
And you want
1 | c.Add |
to be thread safe
In the Package Manager Console write:
Install-Package ThreadSafeObject
Then modify your code to:
1 2 3 | Calculation c = new Calculation(); dynamic ts = new ThreadSafe(c); ts.Add(); |
It is a toy project- however, it has tests to prove it is correct.
You can download the code source from https://github.com/ignatandrei/ThreadSafeObject/