开发者

Azure : The process cannot access the file "" because it is being used by another process

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.zi开发者_如何学Pythonp' 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.


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).


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);


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜