troubleshooting Question

VB.NET - Retrieving Computers from Active Directory crashes app

Avatar of wally_davis
wally_davisFlag for United States of America asked on
Visual Basic.NET
5 Comments2 Solutions1528 ViewsLast Modified:
I am using VB.NET to retrieve Computers from Active Directory and pumps all of the computer names into a text file.
It then crashes the app and produces the following error:

"ContextSwitchDeadlock was detected - The CLR has been unable to transition from COM context 0x1a0928 to COM context 0x1a0a98 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."
Not sure what all this means, but, if there is a more efficient way to perform this routine so it doesn't crash my vb.net module, I would be one estatic person.

My thanks to anyone who can help,
Wallace
Public Function runAdQuery() As DataTable
        Dim entry As New DirectoryEntry("LDAP://DC=MyDomain,DC=Com")
        Dim searchOU As New DirectorySearcher(entry)
        searchOU.Filter = ("(objectClass=Computer)")
        searchOU.PageSize = 100000
 
        Dim adTable As New DataTable("ADTable")
        Dim pcName As DataColumn = adTable.Columns.Add("Workstation_Name", GetType(String))
        pcName.AllowDBNull = True
        pcName.Unique = True
 
        Dim resEnt As SearchResult
        Dim adComputers As StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(adPcList, False)
        For Each resEnt In searchOU.FindAll()
            Try
                Dim de As DirectoryEntry = resEnt.GetDirectoryEntry
                Dim adRow As DataRow = adTable.NewRow
                adRow("Workstation_Name") = de.Properties("Name").Value.ToString
                adTable.Rows.Add(adRow)
                adComputers.WriteLine(resEnt.GetDirectoryEntry.Name) '(adRow.ItemArray(0))
                adComputers.Flush()
            Catch ex As Exception
 
            End Try
        Next
 
        Return runAdQuery
ASKER CERTIFIED SOLUTION
Sancler

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros