public IDisposable Acquire()
{
string dir = Path.GetDirectoryName(filepath);
lock (this)
{
#if !WindowsCE
while (stream != null)
Monitor.Wait(this);
#endif
while (true)
{
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
try
{
Debug.Assert(stream == null, "Stream was not null--programmer error");
stream = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None, 8, false);
return disposeHelper;
}
catch (IOException ioe)
{
int errorCode = SafeNativeMethods.GetErrorCode(ioe);
switch (errorCode)
{
case 32:
case 33:
case 32 | 0x1620:
case 33 | 0x1620:
Thread.Sleep(50);
continue;
default:
throw;
}
}
}
}
}