using xmlReader from a windows service and locking file until service is stopped!

Posted on 2005-04-11
Last Modified: 2010-08-05
I have the following code in the windows service written in VB.NET:

Dim textReader As New XmlTextReader(path)
        Do While textReader.Read
            If textReader.NodeType = XmlNodeType.Element Then
                If textReader.Name = key Then
                    Return textReader.ReadElementString(key)
                End If
            End If
        textReader = Nothing

which locks the config file.  I try to write to it later and get file not found error. Then I stop the service and the config file is available again.  I thought closing the reader and setting it to nothing would work.  Is this the correct way to read this XML or do I need to stop the service before writing to the XML file.  I really do not want to stop the service.  I could also use another config file but that would add extra maintenance.  

Question by:courchjo
    1 Comment

    Accepted Solution

    I found my problem.  I need to put function in try and catch.  The textReader.close and textreader = nothing is never being called after the return.  Since app is a service the reader never gets closed and the file is not released.


    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now