static ReaderWriterLockSlim WriteLock = new ReaderWriterLockSlim();
/// <summary>
/// 点的坐标写入txt
/// </summary>
/// <param name="xjListPoints"></param>
/// <param name="xjFileFullPath"></param>
public void xjWritePointsToTxt(List<IPoint> xjListPoints, string xjFileFullPath)
{
try
{
if (!WriteLock.IsWriteLockHeld)
{
WriteLock.EnterWriteLock(); //进入写入锁
System.IO.FileStream xjExportFileStream = new System.IO.FileStream(xjFileFullPath, FileMode.OpenOrCreate);
StreamWriter xjExportStreamWriter = new StreamWriter(xjExportFileStream);
for (int i = 0; i < xjListPoints.Count; i++)
{
IPoint xjExportPoint = xjListPoints[i];
double xjExportX = xjExportPoint.X;
double xjExportY = xjExportPoint.Y;
//double xjExportZ = xjExportPoint.Z;
string xjPointLine = xjExportX.ToString() + " " + xjExportY.ToString();//行:x y z
xjExportStreamWriter.WriteLine(xjPointLine);
}
xjExportStreamWriter.Flush();//清空缓冲区
xjExportStreamWriter.Close();//关闭流
xjExportFileStream.Close();
}
}
catch (Exception e)
{
if (WriteLock.IsWriteLockHeld)
WriteLock.ExitWriteLock(); //退出写入锁
Console.WriteLine(e.Message);
}
finally
{
if (WriteLock.IsWriteLockHeld)
WriteLock.ExitWriteLock(); //退出写入锁
}
}