我创建了一个服务,它的作用是将信息写入 xml 文件。
有时,它似乎主要发生在计划外重新启动时,服务无法启动,因为使用的文件被“锁定”。由于我的服务设置为“自动启动”,因此系统仍在启动时发生此错误。
这是在windows 2003下。
有谁知道为什么会这样?
谢谢。
The process cannot access the file 'D:\myService\eventlog.xml' because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.Xml.XmlTextWriter..ctor(String filename, Encoding encoding)
at System.Data.DataTable.WriteXml(String fileName, XmlWriteMode mode, Boolean writeHierarchy)
at System.Data.DataTable.WriteXml(String fileName)
at myService.c_control.addXmlLog(eventStatus timeStatus)