473,386 Members | 1,830 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,386 software developers and data experts.

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.

Thanks,

David Miller

Nov 20 '05 #1
1 991
Have you tried changing the Signature to

StartSearchAsync(ByRef query As CQuery ??

Nov 20 '05 #2

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

Similar topics

0
by: Zuel | last post by:
Sup everyone! I wrote this code for Tomcat appserver but I am told from an associate that it has threading issues. The basic idea is to store a read only data table for everyone to use. It...
19
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException....
4
by: Antal Rutz | last post by:
Hi, All! I'm new to threading. I have some design questions: Task: I collect data and store them in an RDBMS (mysql or pgsql) The question is how to do that with threading? The...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
0
by: CK | last post by:
I have the following code in a windows service, when I start the windows service process1 and process2 work fine ,When process 1) and 2) get completed process 3) starts and sofar so good. the...
13
by: John | last post by:
I've got some reasonably complex business logic in my C# code, in a class called by a ASP.NET page. This takes around 3-4 seconds to execute. It's not dependent on SQL calls or anything like that....
4
by: JimD | last post by:
Is this safe? Any pitfalls? I have done threading in regular C# apps, but haven't had a needs to do threading in ASP.Net, until now. The issue I have ran into is this: Our corporate portal...
2
by: WXS | last post by:
When I see things in .NET 2.0 like obsoletion of suspend/resume because of the public reason MS gives of they think people are using them inappropriately.. use mutex, monitor and other...
19
by: frankiespark | last post by:
Hello all, I was perusing the internet for information on threading when I came across this group. Since there seems to be a lot of good ideas and useful info I thought I'd pose a question. ...
126
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard:...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.