title: file lock on write and read
body: <p>I have an xml file that has different marks in it that i need to update and need to pick up. this mark is from an api and is used so i only get new data. however when i try to write away the data or read the file it get locks all the time. these are the 2 functions that i use to write or read from the file.</p>
  
  <pre><code>    private void SetMark(string name, string mark)
      {
          var marksfile = (string)_appSettings.GetValue("MarksFile", typeof(string));
  
              _marks = new dsMarks();
              try
              {
                  if (File.Exists(marksfile))
                  {
                      using (var reader = new StreamReader(marksfile))
                      {
                          _marks.ReadXml(reader);
                      }
                  }
              }
              catch (Exception)
              {
                  _marks = null;
                  throw;
              }
  
          var row = _marks.Mark.FindByName(name);
          row.TimeMark = mark;
          _marks.AcceptChanges();
          using (var writer = new StreamWriter(marksfile))
          {
              _marks.WriteXml(writer);
          }
      }
  
      private string GetMark(string name)
      {
          var marksfile = (string)_appSettings.GetValue("MarksFile", typeof(string));
              _marks = new dsMarks();
              try
              {
                  if (File.Exists(marksfile))
                  {
                      using (var reader = new StreamReader(marksfile))
                      {
                          _marks.ReadXml(reader);
                      }
  
                  }
              }
              catch (Exception)
              {
                  _marks = null;
                  throw;
              }
          var row = _marks.Mark.FindByName(name);
          var mark = row.TimeMark;
  
          return mark;
      }
  </code></pre>