C# Windows Service is locking file

  • Thread starter Thread starter JM
  • Start date Start date
J

JM

I have created a Windows Service which uses xml file as a data source.
The service is running on .NET 2.0 and uses LocalSystem account.

It was running fine but now it has started locking the xml file
sometimes. When I stop the service it unlocks the file.The service is
running all time. And it locks xml file sometimes not always.

I would really appreciate if anybody can guide me here.

Thanks
JM
 
Seems that class that works with fike is not disposed correctly.
Do u use using approach when work with your XML?

What's the version u run - debug or server?

--
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
Hi Michael,

Thanks for the quick response.

I am using "ds.ReadXml(FileName)" for reading xml file and then using
"ds.WriteXml(FileName)" for writing XML from dataset. Where ds =
dataset and FileName = name of xml file.

I am compiling Windows Service in "debug" mode only and running that
version only. Whats the "server" mode? Is it the same as "release"
mode?

I have created windows service using VS 2005 in C# using .NET Framework
2.0.

Is there any better way of reading and writing XML. Dataset is
disconnected so there should not be any problem (I may be wrong).

Any help would be appreciated.

Regards
JM
 
Try to rebuild you app in "release" mode (I mistyped with "Server" mode)
In debug CLR can prolong object GC to the end of code block, not scope, thus
your file can be open when you are trying to write into in.

--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
Thanks for your help. I will test the app build in Release mode. I will
keep you posted about the results.

Thanks
JM
 
Back
Top