VB.NET - Retrieving Computers from Active Directory crashes app
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,
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