I have an enumeration that is shared between multiple threads:
public enum Action
{
Read,
Write,
None
}
Within a class I have a variable of Action type:
public Action _action;
This is a shared variable, that is, it is updated and read from multiple threads.
For example, from one thread I do:
_action = Action.Read
And from another one:
if (_action == Action.Read)
{
}
else if (_action == Action.Write)
{
}
else if (_Action == Action.None)
{
}
else
{
}
So I would like to use Interlock to update and/or read it from different threads at the same time. How can I do it through a property?
I have seen many posts, for example below one:
How to apply InterLocked.Exchange for Enum Types in C#?
Problem here is that enumeration needs to cast to an int, but I would like to keep enumeration without casting. Is it possible? If so, could you post some example? Also Is it possible to combine volatile with interlock? I mean apply interlock on a volatile enumeration.