I have made a C# program, and i want to limit the number of concurrent users, for licensing reasons.
The program itself (the exe-file) is installed locally, and the datafiles (not a database) is stored on a shared drive on the server.
My idea was to have a lock-file, that each instance of the program would keep a ReadWrite handle to.
And then I would count the open file handles to the lock-file. When the number of handles would reach 5, i would reject more handles, and not allow the program to start,
Something like:
FileStream fileStream = new FileStream(@"f:\blabla\lock.txt", FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);
if (filestream.CountFileHandles()>5) return false;
But i can't figure out how to count the open files handles to the lock-file.
I don't want to write anything in the lock-file. Just count the handles.
Or maybe I am following a wrong path, and somebody can guide me to a better solution, how to limit the number of concurrent users.