473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Thread not ending...

I'm building a VB 2005 app (.Net 2.0) that performs searches against our
active directory.

It's pretty basic. I have a UI form that takes search parameters and feeds
them to a class I created. I built a "broker" class that handles the thread
processing which has a reference to the UI and to the Searcher class.

When the user clicks search, it calls a method on the broker to create a
thread that executes the search. The searcher keeps a ref to the broker to
feed results back to it which fires off a delegate to the ref of the client
UI to populate a listview with the results.

On the broker, there is a shared variable called CancelRequested. When the
client clicks the cancel button on the UI it sets the CancelRequested to True
on the broker.

On the Searcher, it checks after each search result to see what the status
of broker.CancelRequested is. If it is true, it exits out of the search loop
and sub and lets the thread terminate normally. Problem is, I can debug the
app and see the searcher evaluate the CancelRequest check and exit the sub, I
can see the thread exit, but the results keep pumping back to the UI.

Any ideas? It may be something to do with the
DirectoryServices.DirectorySearch object I am using, but I can't seem to get
the dang thing to stop. I've waited for several minutes after the cancel
request is processed. I've done a few other apps with this architecture and
they work great.

Here is the "offending" routine:

Private Sub Search()
Dim de As New DirectoryEntry(SearchRoot)
Dim ds As New DirectorySearcher(de)
Dim col As SearchResultCollection = Nothing

ds.Filter = BuildFilter()

Console.WriteLine(ds.Filter)

ds.SearchScope = SearchScope.Subtree
ds.PageSize = 50

Dim sr As SearchResult = Nothing
col = ds.FindAll()

For Each sr In col
If Broker.CancelRequested = True Then
Broker.Completed(True)
Exit Sub
End If

Dim item As New ListViewItem
Dim i As Integer = 0
For i = 0 To Conditions.IncludedAttributes.Length - 1

item.SubItems.Add(CType(sr.Properties(Conditions.I ncludedAttributes(i))(0),
String))
Next
Broker.ResultFound(item)
Next

End Sub
Feb 21 '06 #1
0 923

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Olivier Parisy | last post by:
Hi, I like to use thread to simplify the handling of independant, blocking tasks. But controling them from a main thread is not always easy to do in a clean way. So I've written some generic...
2
by: ice88 | last post by:
I would like to execute some code when a thread terminates, in the context of that thread - I guess similar to an ExitThread handler - is it possible in a C# .NET application? I can see a way to...
1
by: GSK | last post by:
I am logging the following error when re-directing via Response.Redirect: "Thread was being aborted at System.Threading.Thread.AbortInternal() at System.Threading.Thread.Abort(Object...
2
by: ice88 | last post by:
I would like to execute some code when a thread terminates, in the context of that thread - I guess similar to an ExitThread handler - is it possible in a C# .NET application? I can see a way to...
3
by: Raj Wall | last post by:
Hi, I have an application that uses a number of sub-threads. What is the best way to do some processing in each thread when the main application is shut down? Is the ThreadAbortException...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.