title: Attempting to retrieve files from TFS workspace stalls application
body: <p>So I am attempting to retrieve the files from a workspace in TFS.  Unfortunately, every attempt that I have made to do this results in a stalled application.  As of right now, this is the code:</p>
  
  <pre><code>    public void GetWorkspaceFiles(string workspaceName)
      {
          VersionControlServer sourceControl = (VersionControlServer)TfsServer.GetService(typeof(VersionControlServer));
  
          var items = sourceControl.GetItems(workspaceName, VersionSpec.Latest, RecursionType.Full)
                                   .Items
                                   .Where(x =&gt; x.ItemType == ItemType.File)
                                   .ToList();
  
          for (int x = 0; x &lt; items.Count; x++)
              items[x].DownloadFile();
  </code></pre>
  
  <p>What happens is that every time I run this application (on multiple machines) it stalls on <code>items[x].DownloadFile()</code>.  All the files in TFS are not locked, everything is fine.  Attempting to use the <code>Workspace.Get()</code> method results in the same thing.  </p>
  
  <p>If I hit pause, x will be a specific value, but I can't access the items collection, as when I do I get "Cannot evaluate expression because the current thread is in a sleep, wait, or join".  When I evaluation the call stack I get:</p>
  
  <pre><code>[In a sleep, wait, or join]
  [External Code]
  GetWorkspaceFiles(string workspaceName) Line 55
  </code></pre>
  
  <p>I am at a loss at what to do further.  Whenever I pause the application, <code>x</code> is always at the same value (the value that it stalls on is different for every application run though).</p>
  
  <p>Anyone have any ideas?</p>
  
  <p><hr>
  <b>Edit:</b> After adding diagnostic logic (based on the link in Grant's answer) I am even more confused than ever.</p>
  
  <p>The workspace I am passing into this method is <code>$/QA/Automated Test Scripts/Regression or System Test Scripts/RDE or Condo</code> (verified through the debugger).</p>
  
  <p>However, when I look at the tfs logs, it looks to be downloading the code file that I am running, as it says: </p>
  
  <pre><code>02/10/2011 12:26:58 (pid 5808, tid 5968, 42180 ms) Recording OperationStatus.Getting for $/QA/Automated Test Scripts/QA Tools/Test Manager/Test Polling Server/fmMain.cs
  </code></pre>
  
  <p>Right after that entry is:</p>
  
  <pre><code>02/10/2011 12:26:58 (pid 5808, tid 5968, 42180 ms) DownloadFiles: 18 ms
  02/10/2011 12:26:58 (pid 5808, tid 5968, 42181 ms) Acknowledgements: 0 ms
  </code></pre>
  
  <p>After that there are no further updates to the log file, and my application is stalled.  What I am confused about is </p>
  
  <p>1) Why is this trying to pull the application code from TFS when I am specifying a completely different TFS workspace</p>
  
  <p>2) Why is this stalling after attempting to retrieve the file?  It's possible that it's because <code>fmMain.cs</code> is open in Visual Studio, but it should still exception out and not get hung up.  I'm able to get latest while the file is open via visual studio normally.</p>
  
  <p><hr><hr>
  <b>Edit2:</b></p>
  
  <p>Ok so I was reading through MSDN and I noticed that the workspace name can be the local path to the files.  So I modified what I passed in as the <code>workspaceName</code> parameter to the local directory of the files.  I still get stalls, but the log file is a lot less clear on why.  I have uploaded the tf.log file <a href="http://dl.dropbox.com/u/6753359/tf.log" rel="nofollow">here</a> (I have obviously changed proprietary information, such as server and project names, but everything else is untouched).  After that last log entry, no further data is written to the log.</p>