467,868 Members | 1,383 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,868 developers. It's quick & easy.

Threading Question/Issue

Dear Sir or Madam:

I am writing an application in VB.Net, and I have an interesting threading situation that I cannot seem to figure out. I have a search class (CSearch) that is responsible for performing asynchronous searches. It has methods as follows...

'Starts a new asyncronous search, and displays the results in a new window.
'The results window can also be suppressed if no results are found
Public Sub StartSearchAsync(ByVal query As CQuery, ByVal openHandler As ObjectOpenedHandler, ByVal suppressEmptyResults As Boolean, ByVal existingSearchID As Integer, ByVal title As String, ByVal startIconIdx As Integer, ByVal endIconIdx As Integer)
'Create a new search delegate
Dim searchDeleg As SearchHandler = New SearchHandler(AddressOf StartSearch)

'Create a new search identifier
Dim ident As CSearchIdentifier
ident = New CSearchIdentifier
ident.AsyncDelegate = searchDeleg
ident.ObjectOpenMethod = openHandler
ident.SuppressEmptyResults = suppressEmptyResults
ident.StartedIconIndex = startIconIdx
ident.FinishedIconIndex = endIconIdx
[Code Omitted]

Dim ar As IAsyncResult
ar = searchDeleg.BeginInvoke(query, New AsyncCallback(AddressOf SearchCompleted), ident) <-- The query object here has two items in its collection.
End Sub

'This method is called whenever a search is completed
Private Sub SearchCompleted(ByVal ar As IAsyncResult)
'Get the search identification object
Dim ident As CSearchIdentifier
ident = DirectCast(ar.AsyncState, CSearchIdentifier)
'Get the delegate back
Dim deleg As SearchHandler
deleg = DirectCast(ident.AsyncDelegate, SearchHandler)
'Get the results from the delegate
Dim results As CollectionBase = deleg.EndInvoke(ar)
'Raise the event
RaiseEvent SearchFinished(ident, results)
End Sub

'Starts a new search and blocks until the operation completes
Public Function StartSearch(ByVal query As CQuery) As CollectionBase
'Perform the search
Dim results As CollectionBase = Nothing
results = CFacade.ExecuteQuery(query) <--- Now the query object has 0 items in its collection.

'Return the results
Return results
End Function

The StartSearchAsync method is called from another class in order to perform the search. The CQuery object has a collection in it exposed through a property that has several search conditions objects in it. My issue is that on the marked line in StartSearchAsync, the query object has two objects in its collection, but when the StartSearch method is invoked through the delegate, the query object somehow loses its two objects in its collection. This is shown in bold on the second marked line.

Does anyone have any ideas about why this might by occurring? If you need any more info on the code, a better explanation, or anything else, just let me know.


David Miller

Nov 20 '05 #1
  • viewed: 875
1 Reply
Have you tried changing the Signature to

StartSearchAsync(ByRef query As CQuery ??

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Zuel | last post: by
19 posts views Thread by Jane Austine | last post: by
4 posts views Thread by Antal Rutz | last post: by
reply views Thread by CK | last post: by
13 posts views Thread by John | last post: by
4 posts views Thread by JimD | last post: by
2 posts views Thread by WXS | last post: by
19 posts views Thread by frankiespark | last post: by
126 posts views Thread by Dann Corbit | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.