Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Is the function called from multiple threads? If yes you may want to declare a static object on class level and place a lock statement around the entire body of that method. Like this:</p> <pre><code>private static Object syncObject = new Object() // this works not - see commented lin public static void DecryptFile(string FileName) { lock(syncObject) { string ToDecrypt = null; using (StreamReader sr = new StreamReader(FileName)) { ToDecrypt = sr.ReadToEnd(); } // here comes the exception using (StreamWriter sw = new StreamWriter(FileName, false)) { string Decrypted = Decrypt(ToDecrypt, true); sw.Write(Decrypted); } } } </code></pre> <p>Also could you, just for fun, comment the StreamReader statement and try to run the method again? If it still doesn't work, check if you've that file open in a texteditor or something alike by using ProcessExplorer or something similiar.</p> <p><strong>edit</strong> could you comment the StreamReader part? So that it looks like this:</p> <pre><code> public static void DecryptFile(string FileName) { //string ToDecrypt = null; //using (StreamReader sr = new StreamReader(FileName)) //{ // ToDecrypt = sr.ReadToEnd(); //} // here comes the exception using (StreamWriter sw = new StreamWriter(FileName, false)) { string Decrypted = Decrypt(ToDecrypt, true); sw.Write(Decrypted); } } </code></pre> <p>also could you try to open an exclusive FileStream on that file before the StreamReader and once after the StreamReader but before the StreamWriter? <a href="http://msdn.microsoft.com/de-de/library/tyhc0kft%28v=vs.110%29.aspx" rel="nofollow">http://msdn.microsoft.com/de-de/library/tyhc0kft%28v=vs.110%29.aspx</a></p> <p>Also could you try and use another file for that method?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload