Note that there are some explanatory texts on larger screens.

plurals
  1. PODirectoryInfo.GetFileSystemInfos and File Renaming
    primarykey
    data
    text
    <p>I seem to be having a timing issue when renaming images and then re displaying them. In my code I use System.IO.File.Move twice to rename some images in a directory. Then later I try to retrieve a list of files in the directory, but when I do so I get some file names that existed after the first rename, and some that existed after the 2nd rename. How do I ensure I get only file names that exist after the 2nd rename? I have contemplated putting in a Thread.Sleep(), but that feels like a hack. In case it helps, I'm using MVC3.</p> <pre><code>public ActionResult UpdateImages () { foreach (file in directory) System.IO.File.Move("oldname", "newname"); foreach (file in directory) System.IO.File.Move("oldname", "newname"); return RedirectToAction("Images", "Manager", new { id = Id }); } public ViewResult Images(int id) { var di = new DirectoryInfo(Server.MapPath("something"))); var files = di.GetFileSystemInfos("*-glr.jpg"); var orderedFiles = files.OrderBy(f =&gt; f.Name); var images = new List&lt;string&gt;(); images.AddRange(orderedFiles.Select(fileSystemInfo =&gt; fileSystemInfo.Name)); ViewData["Images"] = images; return View(); } </code></pre> <p><em>edit</em></p> <p>I wish I could remove my own question. It seems I have solved this and the answer isn't even related to the information I provided in the question.</p> <p>It seems that I ended up sending both a Get and a Post to the server. The Post kicked off the work, but the response from the post got aborted since the Get was also fired. Since the Get finished quickly, it would catch the system in an in-between state.</p> <p>The offending line of code was a anchor element that had both an href and a javascript click handler (through jQuery) attached to it.</p>
    singulars
    1. This table or related slice is empty.
    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