[Mono-dev] Problems with FileStream.Lock();
Terry-Watts.com
Terry at Terry-Watts.com
Mon Jan 7 21:50:21 UTC 2013
I have a class that work fine in C# under Windows but not under Monodroid.
A simplified version of the class is:
|public class LockedStream : FileStream
{
ulong LockCount = 0;
bool _IsNewFile;
LockedStream( bool IsNewFile, string path, FileMode mode, FileAccess access, FileShare share)
: base( MakePath( path), mode, access, share)
{
_IsNewFile = IsNewFile;
}
public LockedStream( string path, FileMode mode, FileAccess access, FileShare share)
: this( !File.Exists( path), path, mode, access, share)
{
}
public static internal LockedStream Open( string FilePathName )
{
return ( new LockedStream( FilePathName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite ) );
}
public void Lock()
{
if( LockCount++ == 0 )
{
int SleepCount = 1;
while( true )
{
try
{
base.Lock( 0, Int64.MaxValue );
break;
}
catch( Exception E)
{
Thread.Sleep( SleepCount++ );
}
}
}
}
public void UnLock()
{
if( LockCount > 0 )
{
if( --LockCount == 0 )
{
try
{
base.Unlock( 0, Int64.MaxValue );
}
catch( Exception )
{
}
}
}
}
}|
Now when I do:
|LockedStream Stream = LockedStream.Open( "Some Path/file name" );
Stream.Lock();|
I get the file created when I call the Open(); but when I call
Stream.Lock(); I hangs in the lock routine forever because base.Lock( 0,
Int64.MaxValue ); throws a lock violation exception even though the file
isn't locked.
Does anybody know why this is happening on Android?
Thanks in advance.
Terry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20130108/00bc2760/attachment-0001.html>
More information about the Mono-devel-list
mailing list