Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF映像服务正在锁定文件_C#_Wcf_Imaging - Fatal编程技术网

C# WCF映像服务正在锁定文件

C# WCF映像服务正在锁定文件,c#,wcf,imaging,C#,Wcf,Imaging,我正在做一项c#wcf服务,在该服务中,我收到一组图像,该服务将它们合并到一个多图像Tiff文件中。在服务结束时,我想删除原始文件,但我收到一个错误,其他进程正在锁定该文件 这是接收图像(作为字节[]列表)并将其写入磁盘的代码 public static List<string> SaveByteImagesToFile(List<byte[]> bytesToCopyIntoFiles, string imageReferenceType, string imageRe

我正在做一项c#wcf服务,在该服务中,我收到一组图像,该服务将它们合并到一个多图像Tiff文件中。在服务结束时,我想删除原始文件,但我收到一个错误,其他进程正在锁定该文件

这是接收图像(作为字节[]列表)并将其写入磁盘的代码

public static List<string> SaveByteImagesToFile(List<byte[]> bytesToCopyIntoFiles, string imageReferenceType, string imageReferenceValue)
        {
            _applicationLogger.Debug(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name);

            string imageFinalPath = string.Empty;
            string joinImagesFilePath = string.Empty;

            List<string> imagesFilePath = new List<string>();

            int count = 1;

            try
            {
                if (bytesToCopyIntoFiles.Count == 0)
                {
                    throw new ArgumentNullException("bytesToCopyIntoFiles");
                }
                else
                {
                    joinImagesFilePath = SettingsManager.GetServiceSetting(AppSettingsKeys.CopyImagesToFilePath, "NO_VALID_FILEPATH");

                    if (joinImagesFilePath.IsValidFilePath(out string errorMessage, true, true))
                    {

                        foreach (byte[] image in bytesToCopyIntoFiles)
                        {
                            var imageFileName = imageReferenceType + "_" + imageReferenceValue + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + count.ToString();
                            imageFinalPath = joinImagesFilePath + Path.DirectorySeparatorChar + imageFileName + ".tiff";

                            using (FileStream stream = new FileStream(imageFinalPath, FileMode.Create, FileAccess.ReadWrite))
                            {
                                stream.Write(image, 0, image.Length);
                                stream.Flush();
                            }

                            imagesFilePath.Add(imageFinalPath);
                            count++;
                        }
                    }
                    else
                    {
                        exceptionMessageType = MainRepository.GetExceptionMessage("E171");
                        throw new IOException(exceptionMessageType.ExceptionMessage + " " + errorMessage);
                    }
                }
                return imagesFilePath;
            }
            catch
            {
                throw;
            }
        }  
public static List SaveByteImagesToFile(List bytesToCopyIntoFiles、string imageReferenceType、string imageReferenceValue)
{
_applicationLogger.Debug(MethodBase.GetCurrentMethod().DeclaringType.Name,MethodBase.GetCurrentMethod().Name);
string imageFinalPath=string.Empty;
string joinImagesFilePath=string.Empty;
列表图像文件路径=新列表();
整数计数=1;
尝试
{
if(bytesToCopyIntoFiles.Count==0)
{
抛出新ArgumentNullException(“ByTestocyIntoFiles”);
}
其他的
{
joinImagesFilePath=SettingsManager.GetServiceSetting(AppSettingsKeys.CopyImagesToFilePath,“无有效文件路径”);
if(joinImagesFilePath.IsValidFilePath(输出字符串errorMessage,true,true))
{
foreach(bytesToCopyIntoFiles中的字节[]图像)
{
var imageFileName=imageReferenceType+“”+imageReferenceValue+“”+DateTime.Now.ToString(“yyyymmddhhmmssff”)+count.ToString();
imageFinalPath=joinImagesFilePath+Path.DirectorySeportorChar+imageFileName+“.tiff”;
使用(FileStream stream=newfilestream(imageFinalPath,FileMode.Create,FileAccess.ReadWrite))
{
stream.Write(image,0,image.Length);
stream.Flush();
}
添加(imageFinalPath);
计数++;
}
}
其他的
{
exceptionMessageType=MainRepository.GetExceptionMessage(“E171”);
抛出新IOException(exceptionMessageType.ExceptionMessage+“”+errorMessage);
}
}
返回图像文件路径;
}
抓住
{
投掷;
}
}  
如何使用或使用什么来阻止服务或任何进程锁定文件。正如您所看到的,我在使用filestream的作用域时没有任何运气


有什么想法吗?谢谢

解决了!通过按特定顺序组织文件,在创建多页tiff时,当逻辑结束时,工作人员已经解锁了资源,我现在可以毫无问题地删除它们。

有时病毒扫描程序会导致此问题。请尝试process monitor以查看谁/什么人正在访问该文件iis工作人员是锁定该文件的人。这就是我在进程监视器中看到的