473,473 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Erroneous Results from Threads

I'm having problems with the following code:

The event handler is called after each turn in the loop ( 0 to 10 )

The results are output to a RichTextBox, but with only 11 iterations
happening, I sometimes get duplicate results

My final output should only have 11 groups of keywords, but sometimes, group
9 or group 10 will have been inserted into the Rich text box 2 or 3
additional times.

Can anyone tell me by reading this code if they can spot what is happening?

From Form1.vb:
----------------------
Dim objKeywords As New Keywords

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim strTemp As String = Keywords.Wizard(TextBox1.Text)
Dim strArray() As String = Split(strTemp, "|")
Dim kwCount As Integer = UBound(strArray) - 1

AddHandler objKeywords.DoneCounting, AddressOf
DoneCountingEventHandler

For i As Integer = 0 To 10
ThreadArray(i) = New System.Threading.Thread(AddressOf
objKeywords.kwLoop
objKeywords.kwRootKeyword = strArray(i)
objKeywords.kwMaxCount = 10
objKeywords.Groups = i
ThreadArray(i).Name = "Thread " & i
ThreadArray(i).Start()
Next

End Sub

Sub DoneCountingEventHandler(ByVal strTemp1 As String)

Dim strTemp2 = Split(strTemp1, "|")
Dim intCount As Integer

For intCount = 0 To UBound(strTemp2) - 1
RichTextBox1.AppendText(strTemp2(intCount) & ControlChars.CrLf)
Next

End Sub

------
From Class1.vb in same project
------

Imports System
Imports System.IO
Imports System.Net

Public Class Keywords
Public kwRootKeyword As String
Public kwMaxCount As Integer
Public Event DoneCounting(ByVal strArray As String)
Public Groups As Integer

Function Wizard(ByVal RootKeyword As String)
...
End Function

Public Sub kwLoop()
Dim strArrayTest As String = "--- Group " & Groups &
ControlChars.CrLf & Wizard(kwRootKeyword)
RaiseEvent DoneCounting(strArrayTest)
strArrayTest = Nothing
End Sub

End Class
Nov 21 '05 #1
0 859

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

Similar topics

5
by: news | last post by:
I'm trying out the Zend Development Environment 4, and for the most part I like it, except for two things. It seems to think certain lines that are perfectly valid are bugs. Like this: while...
2
by: CK | last post by:
I am a "newbie" to python and today I had the need to write a program which generated a lot of tcp connections to a range of addresses (10.34.32.0/22) in order to troubleshoot a problem with a...
1
by: Naeem | last post by:
Using the ISeries Access Driver v9.00.04.00 when selecting a column which contains null i get erroneous data. If I keep refreshing the query the results returned with keep changing for the null...
31
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
3
by: Rick | last post by:
Hello, I ran Microsoft's free "Web Application Stress" tool to see how asp.net/c# performed against html. Are these results typical? Network: WAS ran on a server with a t3 Internet...
1
by: Alvin A. Delagon | last post by:
Is there any way to fetch the Return results of spawned threads within the parent script? I would like to do that because I'm having problems with Threads that do queries to a database, I often...
1
by: CEBreedlove | last post by:
I'm trying to trow in another thread into my program. What it's for is to ping a list of IPs. When it runs the Ping portion of the code, it assigns a value of 1 or 2 (pingable / not pingable) to a...
12
by: colin | last post by:
Hi, Ive got a difference in results depending on wether I run my app in the debugger, or run it seperatly (or with <ctrl-f5>) the results in the debugger seem to be more correct, although the...
7
by: DanicaDear | last post by:
I have a query HOTSTICK_ORDER_DETAILS which calculates how many hotsticks a customer must pay for. The name of the field is QTY_CHARGED. (It is calculated by knowing how many sticks they order, how...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.