title: Program stop working: System.IO.__Error.WinIOError
body: <p>I don't have great experience in C# and handled services in MS but I have a peace of code that is called many times inside a bigger process:</p>
  
  <pre><code>private static void InvokeRTF2HTMLParseApplication(string rtfFileName, string htmlFinalFileName)
  {
      string strRTFParseApplicationPath = AppDomain.CurrentDomain.BaseDirectory + "rtfParse2Xhtml.exe";
      if (File.Exists(strRTFParseApplicationPath))
      {
  
          try
          {
              Process process = new Process();
              process.StartInfo.FileName = strRTFParseApplicationPath;
              process.StartInfo.Arguments = "\"" + rtfFileName + "\"" + " " + "\"" + htmlFinalFileName + "\"";
              process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
              process.Start();
              process.WaitForExit();
          }
          catch( Exception e )
          {
              using (StreamWriter w = File.AppendText("\\log.txt"))
              {
                  Log(e.ToString(), w);
              }
          }
      }
  }
  </code></pre>
  
  <p>This calls a <code>rtfParse2Xhtml.exe</code>file to parse a rft and save as html file.
  Randomly (And I can confirm that) sometimes I get the next error message:
  <a href="https://i.stack.imgur.com/NLGgR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NLGgR.png" alt="enter image description here"></a></p>
  
  <p>And the process stops in <code>process.Start()</code> line, and breaks.
  This is my event log message error:</p>
  
  <pre><code>Application: rtfParse2Xhtml.exe
  Framework Version: v4.0.30319
  Description: The process was terminated due to an unhandled exception.
  Exception Info: System.IO.IOException
  Stack:
     at System.IO.__Error.WinIOError(Int32, System.String)
     at System.IO.FileStream.Init(System.String, System.IO.FileMode, System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32, System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean, Boolean)
     at System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess)
     at EmpRtf2Xhtml.rtfParseInput..ctor(System.String)
     at EmpRtf2Xhtml.rtfParse2Xhtml.Main(System.String[])
  </code></pre>
  
  <p>In command line I call the conversion process using the <code>rtfParse2Xhtml.exe</code> and using the same <code>rtf</code> file when the program stops and everything works fine. So, I think isn't a strange char or symbol in the <code>rtf</code> file that prevents the conversion.</p>
  
  <p>I also think that isn't folder permissions because this occurs always on the same folders, multiple times and not with the same test case.
  This occurs in Windows 7 machine and in a Windows Server 2012R2.</p>
  
  <p>My <code>rtfParse2Xhtml</code> code is this:</p>
  
  <pre><code>if (File.Exists(args[1]))
  {
      Console.WriteLine("RtfParser: Update Files " + args[1] + ".");
  }
  string fileName= args[0];
  string fileName2 = args[1];
  rtfParse2Xhtml.fInput = new rtfParseInput(fileName);
  rtfParse2Xhtml.fOutput = new rtfParseOutput(fileName2, false, Encoding.GetEncoding(28591));
  Console.WriteLine("RtfParser: Start");
  int num = rtfParse2Xhtml.TrataGeral();
  Console.WriteLine("".PadRight(70, '-'));
  Console.WriteLine("RtfParser: Stop with RC=" + num);
  result = num;
  </code></pre>
  
  <p>The <code>rtfParseInput</code> constructor class:</p>
  
  <pre><code>public rtfParseInput(string fileName)
  {
      this.fileInput = new FileStream(fileName, FileMode.Open, FileAccess.Read);
  }
  </code></pre>