File locking issue

  • Thread starter Thread starter oliviers
  • Start date Start date
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,
 
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
 
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.
 
Back
Top