File locking issue

O

oliviers

Hi,

I'm trying to filter a xml file using a xml transform object in
vb.net.
The process is running great till I try to delete the xml file when
the job is finished.

I set all my objects to nothing, call GC.collect and finally call
Kill(xmlfilename).
I get an IO error telling the file was unavailable because locked by
another process.

is there a way to detect which object is still locking the file?

Thanks,
 
C

Cor Ligthert[MVP]

Olivers,

Non of the methods you have called are affectiong the locking.

At least you have to close a file to get it free.

Cor
 
P

Phill W.

oliviers said:
I'm trying to filter a xml file using a xml transform object in
vb.net.
The process is running great till I try to delete the xml file when
the job is finished.
I set all my objects to nothing, ...

Setting objects to Nothing in .Net is an [almost] complete waste of
time. You achieve nothing (no pun intended) by doing it.
All you do is make the object /eligible/ for garbage collection, which
should get rid of the object in its own good time.

... call GC.collect ...

IMHO, and unless you're /very/ sure you know what you're doing, you
should never need to call GC.Collect yourself. There are hidden costs
associated with calling it unnecessarily, e.g. you can promote every
variable in your application to "Gen 2", thereby requiring every
subsequent garbage collection to page each and every variable in and out
of memory just to examine it.
... and finally call Kill(xmlfilename).

When you are finished with an object, if it has a defined Dispose (or,
possibly, Close) method, then call that.

My guess would be that you have an XmlWriter (or similar) still open to
the target file.

HTH,
Phill W.
 

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

Top