本文整理汇总了C#中System.IO.FileStream.SetLength方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.FileStream.SetLength方法的具体用法?C# System.IO.FileStream.SetLength怎么用?C# System.IO.FileStream.SetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileStream
的用法示例。
在下文中一共展示了System.IO.FileStream.SetLength方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: retrylogthreadproc
private static void retrylogthreadproc()
{
#if DEBUG
//System.Threading.Thread.Sleep(1000 * 8);
#endif
for (; ; )
{
try
{
using (System.IO.FileStream fs = new System.IO.FileStream(logFilePath,
System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
{
_retryloginitpos = fs.Length;
}
}
catch (System.IO.FileNotFoundException)
{
_retryloginitpos = 0;
}
catch
{
System.Threading.Thread.Sleep(1000 * 1);
continue;
}
break;
}
StringBuilder sbbuf = new StringBuilder(0x400);
for (; ; )
{
int retrylogbufLength;
bool mystop;
lock (retrylogbuf)
{
retrylogbufLength = retrylogbuf.Length;
mystop = retrylogstop;
}
if (_retrylogcharpos < retrylogbufLength)
{
try
{
if (_retrylogcharpos < 0) // Need to rewrite all?
{
using (System.IO.FileStream fs = new System.IO.FileStream(logFilePath,
System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite, System.IO.FileShare.Read))
{
long fsLength = fs.Length;
if (0 == fsLength)
{
// File might have been deleted.
_retryloginitpos = 0;
}
else if (fsLength < _retryloginitpos)
{
// File changed some unknown way.
_retryloginitpos = fsLength;
}
else
{
fs.SetLength(_retryloginitpos);
}
}
_retrylogcharpos = 0; // Rewrite all.
}
sbbuf.Length = 0;
string sendstring;
lock (retrylogbuf)
{
int sendchars = retrylogbuf.Length - _retrylogcharpos;
if (sendchars > _maxretrylogsendchars)
{
sendchars = _maxretrylogsendchars;
}
for (int i = 0; i < sendchars; i++)
{
sbbuf.Append(retrylogbuf[_retrylogcharpos + i]);
}
sendstring = sbbuf.ToString();
}
#if DEBUG
if (!_debugretrylogthrown)
{
if (-1 != sendstring.IndexOf("kill", StringComparison.OrdinalIgnoreCase))
{
_debugretrylogthrown = true;
System.Threading.Thread.Sleep(1000 * 8);
throw new System.IO.IOException("Debug exception for retrylog");
}
}
#endif
_NormalLog(sendstring);
_retrylogcharpos += sendstring.Length;
//.........这里部分代码省略.........