File locking and Bitmap objects

A

alex

I hade some problems with file locking and did a simple test using
process explorer tool from sysinternals.

Bitmap BitmapInWork = new Bitmap(Server.MapPath(fileFullPath));
//at this point file referenced by fileFullPath is locked by aspnet
worker process

BitmapInWork = ResizeImage(BitmapInWork, intTargetWidth,..);
//at this point it is not locked anymore, at least process explorer
doesnt find any handles. and I can delete the file from the disk.

So what hapened to the lock? Was the BitmapInWork.Dispose()called
behind the scene? The question is do i need to use new variable on each
resize and dispose old instance like:

BitmapInWork2 = ResizeImage(BitmapInWork, intTargetWidth,..);
BitmapInWork.Dispose();
BitmapInWork3 = ResizeImage(BitmapInWork2, intTargetWidth,..);
BitmapInWork2.Dispose();

and so on or can I just use the same BitmapInWork for all work?

Thanks.
 
E

Elton Wang

Does your aspnet account have permission to
access 'fileFullPath'? If not, you have to give permission.

Elton Wang
(e-mail address removed)
 
B

bruce barker

hard to say whats happening without seeing your ResizeImage code. but yes
you need to call Dispose as soon as possible, or use a stream and close it.

-- bruce (sqlwork.com)

| I hade some problems with file locking and did a simple test using
| process explorer tool from sysinternals.
|
| Bitmap BitmapInWork = new Bitmap(Server.MapPath(fileFullPath));
| //at this point file referenced by fileFullPath is locked by aspnet
| worker process
|
| BitmapInWork = ResizeImage(BitmapInWork, intTargetWidth,..);
| //at this point it is not locked anymore, at least process explorer
| doesnt find any handles. and I can delete the file from the disk.
|
| So what hapened to the lock? Was the BitmapInWork.Dispose()called
| behind the scene? The question is do i need to use new variable on each
| resize and dispose old instance like:
|
| BitmapInWork2 = ResizeImage(BitmapInWork, intTargetWidth,..);
| BitmapInWork.Dispose();
| BitmapInWork3 = ResizeImage(BitmapInWork2, intTargetWidth,..);
| BitmapInWork2.Dispose();
|
| and so on or can I just use the same BitmapInWork for all work?
|
| Thanks.
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top