473,396 Members | 2,023 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,396 software developers and data experts.

ProducerConsumer Threads

Hi all

I wrote an App that checks some Emailaddresses from our Database ( more
than 500'000). So I wrote a Multithread App.

I have a Queue defined as follow:

ProducerConsumer prcEmailProcess = new ProducerConsumer();

I start the Threads with the following Command:

for (int i = 0; i < MaxThread; i++)
new Thread(new ThreadStart(EmailChecker)).Start();

Then I add for each Thread a null object to signalize the End:

for (int i = 0; i < MaxThread; i++)
prcEmailProcess.Produce(null);

The EmailChecker Code looks as follow:

void EmailChecker()
{
while (bolCheckEmail)
{
object o = prcEmailProcess.Consume();

if (o == null)
{
lock (listDNSLock)
{
if (intEnd.Equals(MaxThread - 1))
{
prcEmailProcess.Reset();
bolCheckEmail = false;
break;
}
else
{

intEnd++;
break;
}
}
}
else
{
objEmail = (ILLFEmail)o;

try
{
//Do somthing }
catch
{
//Handle the Error
}
finally
{
//Clean up
}
}
}
}
Now I would like to show on the MainForm in a lable which thread is
working on with Emailaddress.
I have for each thread a lable.

How can I do this?

I wait till the variable bolCheckEmail is false. But somtimes the
variable is false but the program seams still to run (when I exit the
main form, there is still a process running).
How can that be?

thanks for your help

Daniel

Dec 1 '06 #1
2 1150
The reason the app is still running is probably because a thread did not die. Maybe give your threads name and use the thread debug window in vs to see whats running.

Looks like you might only be killing the last thread??

if (intEnd.Equals(MaxThread - 1))
{
prcEmailProcess.Reset();
bolCheckEmail = false;
break;
}
else
{

intEnd++;
break;
}

You probably want to use events to communicate
between threads. Add a event to this class and have it raise when the address changes or whatever. The form subscribes to the event and updates whatever controls. Remember to use the Form.Invoke too.

Thanks
Ziad
---
Posted via DotNetSlackers.com
Dec 1 '06 #2
Ziad schrieb:
The reason the app is still running is probably because a thread did not die. Maybe give your threads name and use the thread debug window in vs to see whats running.

Looks like you might only be killing the last thread??

if (intEnd.Equals(MaxThread - 1))
{
prcEmailProcess.Reset();
bolCheckEmail = false;
break;
}
else
{

intEnd++;
break;
}

You probably want to use events to communicate
between threads. Add a event to this class and have it raise when the address changes or whatever. The form subscribes to the event and updates whatever controls. Remember to use the Form.Invoke too.

Thanks
Ziad
---
Posted via DotNetSlackers.com

Hi Ziad
Thanks for the answer.

With the

else
{
intEnd++;
break;
}
I quit the while loop and with this the Thread should quit (as far as I
understand). The bool variable I use onely to see when the last Thread
finishes.
The solution with events sounds interresting. Is there somwhere a easy
example?

cheers daniel

Dec 1 '06 #3

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

Similar topics

3
by: Ronan Viernes | last post by:
Hi, I have created a python script (see below) to count the maximum number of threads per process (by starting new threads continuously until it breaks). ###### #testThread.py import...
0
by: Al Tobey | last post by:
I was building perl 5.8.2 on RedHat Enterprise Linux 3.0 (AS) today and noticed that it included in it's ccflags "-DTHREADS_HAVE_PIDS." I am building with -Dusethreads. With newer Linux...
6
by: m | last post by:
Hello, I have an application that processes thousands of files each day. The filenames and various related file information is retrieved, related filenames are associate and placed in a linked...
34
by: Kovan Akrei | last post by:
Hi, I would like to know how to reuse an object of a thread (if it is possible) in Csharp? I have the following program: using System; using System.Threading; using System.Collections; ...
7
by: Mr. Mountain | last post by:
In the following code I simulate work being done on different threads by sleeping a couple methods for about 40 ms. However, some of these methods that should finish in about 40 -80 ms take as long...
3
by: bygandhi | last post by:
Hi - I am writing a service which will check a process and its threads for their state ( alive or dead ). The process has 5 .net managed threads created using thread.start and each have been...
10
by: [Yosi] | last post by:
I would like to know how threads behavior in .NET . When an application create 4 threads for example start all of them, the OS task manager will execute all 4 thread in deterministic order manes,...
3
by: mjheitland | last post by:
Hi, I like to know how many threads are used by a Threading.Timer object. When I create a Threading.Timer object calling a short running method every 5 seconds I expected to have one additional...
10
by: Darian | last post by:
Is there a way to find all the thread names that are running in a project? For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and T5 are running...I want to be able to know that...
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
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
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
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.