In my code, I want to check whether if a task (in an other thread) is currently running or not.
I was considering using a Dictionary<String, bool>
, and checking the boolean value. However, since I don't know all the possible tasks at startup, I will have to populate this Dictionary on the fly when the task is started for the first time and query it like this:
Boolean status;
if (_tasks.TryGetValue(lockName, out status))
{
return status;
}
return false;
Since, instead of having this bool, the mere existence of the entry can be informative, I am considering using Hashset<String>
and adding/removing values instead of setting the flag.
return _tasks.Contains(name)
I am wondering which of these two approaches would yield the best results. I expect approximately the same number of write operations than reads.