title: Thread aborted error during System.IO.File.WriteAllText(string name, string text)
body: <p>I am getting the below error while trying to write to a file on the system. The code was working till time and all of a sudden I am continuously getting this error. Can anyone let me know as to what might have gone wrong?</p>
  <h2>Error:</h2>
  <p>Thread was being aborted.</p>
  <h2>Stack Trace:</h2>
  <blockquote>
  <p>at Microsoft.Win32.Win32Native.CreateFile(String lpFileName, Int32 dwDesiredAccess, FileShare dwShareMode, SECURITY_ATTRIBUTES securityAttrs, FileMode dwCreationDisposition, Int32 dwFlagsAndAttributes, IntPtr hTemplateFile)</p>
  <p>at Microsoft.Win32.Win32Native.SafeCreateFile(String lpFileName, Int32 dwDesiredAccess, FileShare dwShareMode, SECURITY_ATTRIBUTES securityAttrs, FileMode dwCreationDisposition, Int32 dwFlagsAndAttributes, IntPtr hTemplateFile)</p>
  <p>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, Boolean useLongPath)</p>
  <p>at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)</p>
  <p>at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)</p>
  <p>at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)</p>
  <p>at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding)</p>
  <p>at System.IO.File.InternalWriteAllText(String path, String contents, Encoding encoding)</p>
  <p>at MyModule.TrySaveFile(String fileName, StringBuilder sb)</p>
  </blockquote>
  <p>In my code I am using this line:</p>
  <pre><code>File.WriteAllText(fileName, sb.ToString());
  </code></pre>