473,399 Members | 3,603 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.

Threading causing results to be different, Please Help

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 global int. It
works great, however it's slow... If I run the ping portion of my code
in a thread, it returns random values for the pingable / non pingable
values...

My code and a screenshot of is located here.
http://csharp.thinkglobaltech.com/viewtopic.php?p=6#6

the 2 on the left are when i run it w/ the thread, the 1 on the right
is without it in a thread. Only .1 and .2 are pingable in this
situation.

Sep 29 '06 #1
1 1061
If you are assigning to a global int, and i presume you are spawning a
thread per ping, then each thread will change the global int as and when it
gets its ping result.

So if you then do soemthing like store that global int as a ping completes
you are likely to get innacurate results, or moreover, accurate results int
he wrong order giving you a wrong looking readng.

I only glanced over your code but when i saw 'global int' variable and
threads i thought that sounds like the issue, especially if this problem
isnt hapeening when it is non threaded. Because in a non threaded it will do
them one at a time, so ping first, change global int, store value at that
point, next ping etc, so it would work.

Try this, make a struct to contain data like:

string ipaddress,
bool pingSuccess,

etc...

Then per ping create a new instance or have an arraylist containing the
structs and add a new one to the list as you need, and on successfull ping
store in that struct the result. I'd also have a event fire everytime a ping
completes to let your gui know that a ping just completed and pass into that
event the struct.

Then on that event being raised update gui with the ping data.

The result should be a list of pinged ip's all updating as and when the
results complete, all in threads alongside each other.

A global value being changed by multiple threads is a bad idea.
<CE*********@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
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 global int. It
works great, however it's slow... If I run the ping portion of my code
in a thread, it returns random values for the pingable / non pingable
values...

My code and a screenshot of is located here.
http://csharp.thinkglobaltech.com/viewtopic.php?p=6#6

the 2 on the left are when i run it w/ the thread, the 1 on the right
is without it in a thread. Only .1 and .2 are pingable in this
situation.

Sep 29 '06 #2

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

Similar topics

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...
17
by: Andrae Muys | last post by:
Found myself needing serialised access to a shared generator from multiple threads. Came up with the following def serialise(gen): lock = threading.Lock() while 1: lock.acquire() try: next...
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...
9
by: Sam Loveridge | last post by:
Hi all. I'm relatively new to delegates and asynchronous threading and am running into an issue. I need to asynchronously call a method (which I'm doing with a delegate and BeginInvoke) and from...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
3
by: Keith Mills | last post by:
Hello, please find attached a basic outline of what I am attempting to accomplish... basically I want to create a number of THREADS (which I can do fine), but I then need a method for them to be...
12
by: Perecli Manole | last post by:
I am having some strange thread synchronization problems that require me to better understand the intricacies of Monitor.Wait/Pulse. I have 3 threads. Thread 1 does a Monitor.Wait in a SyncLock...
4
by: rh0dium | last post by:
Hi all, I have a problem with putting a job in the background. Here is my (ugly) script which I am having problems getting to background. There are threads about doing python script.py & ...
5
by: Miro | last post by:
I will try my best to ask this question correctly. I think in the end the code will make more sence of what I am trying to accomplish. I am just not sure of what to search for on the net. I...
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: 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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.