我有一个ASP.NET Web应用程序(C#),它使用WIC(Windows Imaging Component)在远程NAS存储上拆分tiff文件。
这是用于拆分的代码,取自此页面: Speed up Tiff file processing with Microsoft Windows Imaging Components (WIC)
using System.IO;
using System.Windows.Media;
using System.Windows.Media.Imaging;
public static void SPlitTiffWIC(string fileName)
{
TiffBitmapEncoder newFileEncoder = null;
FileInfo fi = new FileInfo(fileName);
using (Stream documentStream = fi.OpenRead())
{
TiffBitmapDecoder originalFileDecoder =
new TiffBitmapDecoder(documentStream,
BitmapCreateOptions.PreservePixelFormat,
BitmapCacheOption.None);
foreach (BitmapFrame frame in originalFileDecoder.Frames)
{
newFileEncoder = new TiffBitmapEncoder();
newFileEncoder.Frames.Add(frame);
using (FileStream stream = File.Create("c:\\tiffs\\"
+ Guid.NewGuid().ToString() + ".tiff"))
{
newFileEncoder.Save(stream);
}
}
}
}
我正在使用UNCAccessWithCredentials类来访问具有所需凭据的存储。
我在相同位置的相同文件上多次测试了代码。代码在大多数情况下工作得很好,但有时它会在tiff文件的随机帧上随机文件失败,但有以下异常:
An unexpected network error occurred.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.FileStream.FlushWrite(Boolean calledFromFinalizer)
at System.IO.FileStream.Dispose(Boolean disposing)
at System.IO.Stream.Close() at System.IO.Stream.Dispose()
at TiffManager.Split(String inputFilePath, String outPutDirectory)
at transdocs.PopulateImages(Int32 trsh_num, String trsh_date)
我用Google搜索了这个异常,但它似乎与存储有关!我只是不知道!我需要你的帮助,考虑这个例外的原因以及如何处理它... 提前谢谢