I have a
class which has the purpose of providing file operations i.e. providing functionality to create the file, read, write and rewrite to the file. So, the main constituent of the class is functions.
However, there is one functionality where I am using a
Timer to make the
thread wait for one second. So, basically I have an
Timer working in conjunction.
Now, since we have to register the
Timer_Elapsed callback to the
Timer, we need a place to do it. Since the class is
static, I can use a
static constructor to do that but this makes me think whether the class should be static at first place.
I am confused whether to make the class static or non-static as it is mostly about giving simple functionality but at the same time
AutoResetEvent have become kind of state elements of the class. I would appreciate suggestions.
Edit Reason why I am using a Timer is:
I am trying to synchronize file access between two processes by using
FileShare.None. In order to do that I am in a loop to reattempt to gain access to the FileStream for which I have to wait 1 second each iteration. I am developing functionality in legacy code so I want to avoid
Thread.Sleep. Also I know that a
mutex would be a better option to synchronize access to a file but I cannot use it as I have so many such files that creating a
mutex for each is not preferred (I am asked to not create mutex).