[
  {
    "Id": "724412",
    "ThreadId": "285969",
    "Html": "\r\n<p>I'm trying to archive log files, and am getting the following error occasionally (not every run, but maybe 1 in 2 or 1 in 3 runs):&#65279;</p>\r\n<pre>Exception calling &quot;Save&quot; with &quot;0&quot; argument(s): &quot;The process cannot access the file because it is being used by another process.&quot;\r\nAt C:\\scripts\\test3.ps1:11 char:17\r\n&#43;         $zf.Save &lt;&lt;&lt;&lt; ()\r\n    &#43; CategoryInfo          : NotSpecified: (:) [], MethodInvocationException\r\n    &#43; FullyQualifiedErrorId : DotNetMethodException\r\n</pre>\r\n<p>&#65279;&#65279;The code in question looks like this:</p>\r\n<div style=\"color:black; background-color:white\">\r\n<pre>    <span style=\"color:orangered\">$zf</span> <span style=\"color:gray\">=</span> new<span style=\"color:gray\">-</span>object Ionic.Zip.ZipFile <span style=\"color:orangered\">$zfile</span>\r\n    <span style=\"color:blue\">if</span>(<span style=\"color:orangered\">$zf</span>.ContainsEntry(<span style=\"color:orangered\">$p2zip</span>) <span style=\"color:gray\">-ne</span> <span style=\"color:orangered\">$true</span>)\r\n    {\r\n        <span style=\"color:orangered\">$out</span> <span style=\"color:gray\">=</span> <span style=\"color:orangered\">$zf</span>.AddFile(<span style=\"color:orangered\">$p2zip</span>)\r\n        <span style=\"color:orangered\">$zf</span>.Save()\r\n    }\r\n    <span style=\"color:orangered\">$zf</span>.Dispose()\r\n    Start<span style=\"color:gray\">-</span>sleep <span style=\"color:gray\">-</span>milliseconds 500\r\n</pre>\r\n</div>\r\n<div style=\"color:black; background-color:white\">where $zfile is the zip filename, $p2zip is the fully-qualified filename to add.</div>\r\n<div style=\"color:black; background-color:white\">The start-sleep eliminates 90% of these errors, but it's a bad way to approach this. I've read where these operations are supposed to be synchronous, so it's not that, but maybe the filesystem or Windows aren't\r\n quite done with the zip file yet. Is there something i need to check to ensure the file is done? Or am i missing something else causing the error? Help!</div>\r\n<div style=\"color:black; background-color:white\">Thanks! -bill</div>\r\n",
    "PostedDate": "2012-01-12T11:36:13.1-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]