Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I get the following error:

 

The CLR has been unable to transition from COM context 0x1a01d0 to COM context 0x1a0340 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

 

when I run the following code:

 

Dim files As ReadOnlyCollection(Of String)

files = My.Computer.FileSystem.GetDirectories(pathString, FileIO.SearchOption.SearchAllSubDirectories)

 

This just gets all the sub-directories in a specified folder. The error only occurs when pathString is set to a folder with a lot of subfolders in it (4000+).

 

I dont know how to interpret the error message to make this code work. I just know that after 60 seconds the program errors out. Can anyone tell me what I need to do to make this work when there is a lot of folders/subfolders? Thanks...

Posted

I don't know how this will work with 4000+ directories, but this works for me. Personally I stay away from the 'My' namespace, regardless this is what I use and it should work the same way.

 

Fire up a new console app and try this out on the dir that gives you trouble and let me know what happens...

 

Imports System.IO

Module Module1
   Sub Main()
       Dim st As String()
       'Change this drive to the directory that errors for you and post back the results.
       st = Directory.GetDirectories("d:\\")

       For Each str As String In st
           Console.WriteLine(str)
       Next

       Console.Read()
   End Sub
End Module

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted
I got the impression from the original post that the code is supposed to search through each subfolder, not simply list the top level subfolders (I can't be sure as I've never used the My namespace). If this is the case you will need to call the method recursively. If this is the case there have been alot of posts about this recently so just search the forum.
Anybody looking for a graduate programmer (Midlands, England)?
  • 4 months later...
Posted

I ofcourse havent tested this on 4000 subfolders but it seems to work pretty quick.

 

First though, the other code posted, I beleive will return the entire path along with the subfolders

 

You might wrather try this

 

Imports System.IO

Public Class Form1


   Sub FolderRefresh()
       list1.Items.Clear()
       Dim dirArr() As String = System.IO.Directory.GetDirectories("C:\Program Files\Your Folder Here\")
       For Each itm As String In dirArr
           list1.Items.Add(System.IO.Path.GetFileName(itm))

       Next
   End Sub



   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Call FolderRefresh()

   End Sub
End Class

 

This will return all Subfolders within a Directory... just the FolderNames not the full path too.

 

Hope this helps

 

vbMarkO

Visual Basic 2008 Express Edition!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...