本文整理汇总了C#中FileStream.Unlock方法的典型用法代码示例。如果您正苦于以下问题:C# FileStream.Unlock方法的具体用法?C# FileStream.Unlock怎么用?C# FileStream.Unlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileStream
的用法示例。
在下文中一共展示了FileStream.Unlock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: runTest
//.........这里部分代码省略.........
{
fs2.Lock(1,1);
iCountErrors++;
printerr( "Error_200ae! Expected exception not thrown");
}
catch (ObjectDisposedException iexc)
{
printinfo( "Info_200af! Caught expected exception, iexc=="+iexc.Message);
}
catch (Exception exc)
{
iCountErrors++;
printerr( "Error_200ag! Incorrect exception thrown, exc=="+exc.ToString());
}
iCountTestcases++;
try
{
fs2.ReadByte();
iCountErrors++;
printerr( "Error_200ah! Expected exception not thrown");
}
catch (ObjectDisposedException iexc)
{
printinfo( "Info_200ai! Caught expected exception, iexc=="+iexc.Message);
}
catch (Exception exc)
{
iCountErrors++;
printerr( "Error_200aj! Incorrect exception thrown, exc=="+exc.ToString());
}
iCountTestcases++;
try
{
fs2.Seek(1, SeekOrigin.Begin);
iCountErrors++;
printerr( "Error_200ak! Expected exception not thrown");
}
catch (ObjectDisposedException iexc)
{
printinfo( "Info_200al! Caught expected exception, iexc=="+iexc.Message);
}
catch (Exception exc)
{
iCountErrors++;
printerr( "Error_200am! Incorrect exception thrown, exc=="+exc.ToString());
}
iCountTestcases++;
try
{
fs2.Unlock(1,1);
iCountErrors++;
printerr( "Error_200an! Expected exception not thrown");
}
catch (ObjectDisposedException iexc)
{
printinfo( "Info_200ao! Caught expected exception, iexc=="+iexc.Message);
}
catch (Exception exc)
{
iCountErrors++;
printerr( "Error_200ap! Incorrect exception thrown, exc=="+exc.ToString());
}
strLoc = "Loc_40000";
iCountTestcases++;
try
{
if(fs2.Handle.ToInt32() != -1)
{
iCountErrors++;
printerr( "ERror_3000a! Incorrect value returned by GetHandle()=="+fs2.Handle);
}
}
catch (ObjectDisposedException iexc)
{
printinfo( "Info_200ao! Caught expected exception, iexc=="+iexc.Message);
}
catch (Exception exc)
{
iCountErrors++;
printerr( "Error_200ap! Incorrect exception thrown, exc=="+exc.ToString());
}
if(File.Exists(filName))
File.Delete(filName);
}
catch (Exception exc_general )
{
++iCountErrors;
Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
}
if ( iCountErrors == 0 )
{
Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
return true;
}
else
{
Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
return false;
}
}
示例2: runTest
public bool runTest()
{
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_0000";
String strValue = String.Empty;
int[] iArrInvalidValues = new Int32[]{ -1, -2, -100, -1000, -10000, -100000, -1000000, -10000000, -100000000, -1000000000, Int32.MinValue};
int[] iArrLargeValues = new Int32[]{ Int32.MaxValue, Int32.MaxValue/2, Int32.MaxValue/10, 10000, 100000 , Int32.MaxValue/20, Int32.MaxValue/100 , Int32.MaxValue/1000 };
Random rand = new Random((int)DateTime.Now.Ticks);
try
{
string strFileName = "testblah.cs";
FileStream fs = new FileStream( strFileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
FileStream fs2 = new FileStream( strFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
iCountTestcases++;
for(int iLoop = 0 ; iLoop < iArrInvalidValues.Length ; iLoop++ )
{
try
{
fs.Lock( iArrInvalidValues[iLoop] , Int64.MaxValue );
iCountErrors++;
}
catch ( ArgumentException )
{
}
catch ( Exception ex )
{
Console.Error.WriteLine( "Error_1000!!!! Unexpected exception " + ex.ToString() );
iCountErrors++ ;
}
}
iCountTestcases++;
for(int iLoop = 0 ; iLoop < iArrInvalidValues.Length ; iLoop++ )
{
try
{
fs.Lock( Int64.MaxValue, iArrInvalidValues[iLoop]);
iCountErrors++;
}
catch ( ArgumentException )
{
}
catch ( Exception ex )
{
Console.Error.WriteLine( "Error_1100!!!! Unexpected exception " + ex.ToString() );
iCountErrors++ ;
}
}
iCountTestcases++;
for(int iLoop = 0 ; iLoop < iArrLargeValues.Length ; iLoop++ )
{
try
{
long lLength = (long)rand.Next() ;
fs.Lock( iArrLargeValues[iLoop] , lLength );
fs.Unlock( iArrLargeValues[iLoop] , lLength );
}
catch ( Exception ex )
{
Console.Error.WriteLine( "Error_1200!!!! Unexpected exception 2" + ex.ToString() );
iCountErrors++ ;
}
}
iCountTestcases++;
for(int iLoop = 0 ; iLoop < iArrLargeValues.Length ; iLoop++ )
{
try
{
long lLength = (long)rand.Next() ;
fs.Lock( lLength, iArrLargeValues[iLoop]);
fs.Unlock( lLength, iArrLargeValues[iLoop] );
}
catch ( Exception ex )
{
Console.Error.WriteLine( "Err_1300!!! Unexpected exception " + ex.ToString() );
iCountErrors++ ;
}
}
iCountTestcases++;
Byte[] bArr = new Byte[200];
for(int i = 0 ; i < bArr.Length ; i++)
bArr[i] = (Byte)65;
try
{
fs.Write(bArr , 0 , bArr.Length );
fs.Lock( 0, 200);
fs.Seek(0, SeekOrigin.Begin);
Byte[] bNewArr = new Byte[20];
for(int i = 0 ; i < 20 ; i++)
bNewArr[i] = (Byte)66;
fs2.Write(bNewArr , 0 , bNewArr.Length );
fs2.Flush();
iCountErrors++ ;
}
catch ( IOException )
{
}
catch ( Exception ex )
{
Console.Error.WriteLine( "Error_1400!!!! Unexpected exception " + ex.ToString() );
//.........这里部分代码省略.........