Hi,
I have never used SpinWait. I am waiting for a lockfile to be free, so we can lock the file with below code (FileShare.None)
This lockfile will always be avaliable in approx. <= 50 milliseconds.
I will be needed to react as fast as possible so I beleive it will be better to use .SpinWait rather than Thread.Sleep(1) as I do now.
I wonder how an accurate use of SpinWait would work in this scenario, to react as fast as possible to be able to lock the file?
String lockfile = "C:/lockfile.txt"; FileStream fs = null;
while (true)
{
try
{
//Try to Lock file
fs = new FileStream(lockFile, FileMode.Open, FileAccess.Read, FileShare.None);
break;
}
catch { Thread.Sleep(1); }
}