Azure:进程无法访问文件“”因为它正在被另一个进程使用

发布于 2024-09-03 14:48:10 字数 1104 浏览 7 评论 0原文

我正在尝试在 Azure 云上运行一个 matlab 编译的 exe,为此需要将 v78.zip 放到云的本地存储上并解压缩,然后才能尝试在云上运行 exe。该程序在本地执行时工作正常,但在部署时在代码中标记的行处出现错误。错误是:

进程无法访问文件“C:\Resources\directory\cc0a20f5c1314f299ade4973ff1f4cad.WebRole.LocalStorage1\v78.zip”,因为它正在被另一个进程使用。

异常详细信息:System.IO.IOException:进程无法访问文件“C:\Resources\directory\cc0a20f5c1314f299ade4973ff1f4cad.WebRole.LocalStorage1\v78.zip”,因为它正在被另一个进程使用。

代码如下:

string localPath = RoleEnvironment.GetLocalResource("LocalStorage1").RootPath;

Response.Write(localPath + " \n");

Directory.SetCurrentDirectory(localPath);

CloudBlob mblob = GetProgramContainer().GetBlobReference("v78.zip");
CloudBlockBlob mbblob = mblob.ToBlockBlob;

CloudBlob zipblob = GetProgramContainer().GetBlobReference("7z.exe");

string zipPath = Path.Combine(localPath, "7z.exe");
string matlabPath = Path.Combine(localPath, "v78.zip");
IEnumerable<ListBlockItem> blocklist = mbblob.DownloadBlockList();


BlobStream stream = mbblob.OpenRead();
>>  FileStream fs = File.Create(matlabPath);    (Exception occurs here)

如果有人能告诉我哪里出错了,那将会很有帮助。

I am trying to get a matlab-compiled exe running on Azure cloud, and for that purpose need to get a v78.zip onto the local storage of the cloud and unzip it, before I can try to run an exe on the cloud. The program works fine when executed locally, but on deployment gives an error at line marked below in the code. The error is :

The process cannot access the file 'C:\Resources\directory\cc0a20f5c1314f299ade4973ff1f4cad.WebRole.LocalStorage1\v78.zip' because it is being used by another process.

Exception Details: System.IO.IOException: The process cannot access the file 'C:\Resources\directory\cc0a20f5c1314f299ade4973ff1f4cad.WebRole.LocalStorage1\v78.zip' because it is being used by another process.

The code is given below:

string localPath = RoleEnvironment.GetLocalResource("LocalStorage1").RootPath;

Response.Write(localPath + " \n");

Directory.SetCurrentDirectory(localPath);

CloudBlob mblob = GetProgramContainer().GetBlobReference("v78.zip");
CloudBlockBlob mbblob = mblob.ToBlockBlob;

CloudBlob zipblob = GetProgramContainer().GetBlobReference("7z.exe");

string zipPath = Path.Combine(localPath, "7z.exe");
string matlabPath = Path.Combine(localPath, "v78.zip");
IEnumerable<ListBlockItem> blocklist = mbblob.DownloadBlockList();


BlobStream stream = mbblob.OpenRead();
>>  FileStream fs = File.Create(matlabPath);    (Exception occurs here)

It'll be great help if someone could tell me where I'm going wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

段念尘 2024-09-10 14:48:10

CloudBlob 不是 IDisposable,因此您不需要 using 语句。 (它们只是引用,因此它们不会分配任何需要释放的资源。)

但是,您应该在 FileStream 周围有一个 using() 块。你确定它被关闭了吗?

这段代码在哪里运行?它只运行一次吗?

顺便说一句,你可以做“container.GetBlobRefence("foo").DownloadToFile(matlabPath);” (预测您将要使用该文件句柄做什么)。

CloudBlob's are not IDisposable, so you don't need a using statement. (They're just references, so they don't allocate any resources that need to be released.)

You should, however, probably have a using() block around the FileStream. Are you sure it's being closed?

Where is this code running? Is it run only once?

BTW, you can just do "container.GetBlobRefence("foo").DownloadToFile(matlabPath);" (anticipating what you're about to do with that file handle).

情释 2024-09-10 14:48:10

围绕大部分内容添加一个 using 子句。您的 zip 文件有一个文件句柄。当使用超出范围时,文件引用也会超出范围。

using(CloudBlob mblob = GetProgramContainer().GetBlobReference("v78.zip"))
{
        CloudBlockBlob mbblob = mblob.ToBlockBlob;

        CloudBlob zipblob = GetProgramContainer().GetBlobReference("7z.exe");

        string zipPath = Path.Combine(localPath, "7z.exe");
        string matlabPath = Path.Combine(localPath, "v78.zip");
        IEnumerable<ListBlockItem> blocklist = mbblob.DownloadBlockList();


        BlobStream stream = mbblob.OpenRead();
}
 FileStream fs = File.Create(matlabPath);

Add a using clause around most of this. You have a file handle to your zip file hanging around. When the using goes out of scope, so will the file reference.

using(CloudBlob mblob = GetProgramContainer().GetBlobReference("v78.zip"))
{
        CloudBlockBlob mbblob = mblob.ToBlockBlob;

        CloudBlob zipblob = GetProgramContainer().GetBlobReference("7z.exe");

        string zipPath = Path.Combine(localPath, "7z.exe");
        string matlabPath = Path.Combine(localPath, "v78.zip");
        IEnumerable<ListBlockItem> blocklist = mbblob.DownloadBlockList();


        BlobStream stream = mbblob.OpenRead();
}
 FileStream fs = File.Create(matlabPath);
ぃ双果 2024-09-10 14:48:10

完成后尝试 fs.close() 。

Try fs.close() once you are done with it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文