Hi, I'm using vs2005 and .net 2.0. I started 2 threadpool threads. How do I
know when they're done with their tasks? Thanks.
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Po pulateContextTa ble));
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Po pulatAdTable));
--
Thanks. 10 3110
Hi Pucca,
the WaitCallBack-handler (PopulateContex tTable e.g.) should signal that at
the and, maybe in a finally block. If this is called from a GUI-Thread you
could call BeginInvoke on one of the Forms methods.
Christof
"Pucca" <Pu***@discussi ons.microsoft.c omschrieb im Newsbeitrag
news:E8******** *************** ***********@mic rosoft.com...
Hi, I'm using vs2005 and .net 2.0. I started 2 threadpool threads. How
do I
know when they're done with their tasks? Thanks.
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Po pulateContextTa ble));
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Po pulatAdTable));
--
Thanks.
Thank you Christof. These 2 threads are started within a form as worker
threads only. They are coded as 2 static method within this form. The 2
threads have no form of its own. How can I then find out when they're both
done with their tasks?
--
Thanks.
"Christof Nordiek" wrote:
Hi Pucca,
the WaitCallBack-handler (PopulateContex tTable e.g.) should signal that at
the and, maybe in a finally block. If this is called from a GUI-Thread you
could call BeginInvoke on one of the Forms methods.
Christof
"Pucca" <Pu***@discussi ons.microsoft.c omschrieb im Newsbeitrag
news:E8******** *************** ***********@mic rosoft.com...
Hi, I'm using vs2005 and .net 2.0. I started 2 threadpool threads. How
do I
know when they're done with their tasks? Thanks.
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Po pulateContextTa ble));
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Po pulatAdTable));
--
Thanks.
You use the Join method on the threads. However, there's a small
problem: if you call Join in the UI thread, then you hang the UI.
The usual solution is to use one of the two threads as a "controller ",
or use a third thread. In the first case, the second thread to be
started can be handed a reference to the first thread, and do a Join
before it signals that it's finished. If the first thread isn't
finished yet, then the second thread will wait on the Join until it is.
Therefore, when the second (controller) thread is finished, you know
that they're both finishes.
If the two threads are not logically related this way, then it might be
nicer to use a third, controller thread: the UI starts the controller,
which then starts the two worker threads. The controller then does two
Joins, one on each worker thread, and when the two Joins complete, it
signals the UI that all is done. This is scalable to an arbitrary
number of worker threads.
On Jan 26, 10:35 am, Pucca <P...@discussio ns.microsoft.co mwrote:
Thank you Christof. These 2 threads are started within a form as worker
threads only. They are coded as 2 static method within this form. The 2
threads have no form of its own. How can I then find out when they're both
done with their tasks?
--
Thanks.
"Christof Nordiek" wrote:
Hi Pucca,
the WaitCallBack-handler (PopulateContex tTable e.g.) should signal that at
the and, maybe in a finally block. If this is called from a GUI-Thread you
could call BeginInvoke on one of the Forms methods.
Christof
"Pucca" <P...@discussio ns.microsoft.co mschrieb im Newsbeitrag
news:E8******** *************** ***********@mic rosoft.com...
Hi, I'm using vs2005 and .net 2.0. I started 2 threadpool threads. How
do I
know when they're done with their tasks? Thanks.
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Po pulateContextTa ble));
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Po pulatAdTable));
--
Thanks.- Hide quoted text -- Show quoted text -
Thank you.
I now need to return SearchResultCol lection from both the thread. But I'm
getting error that my code calling the thread has the wrong return
type.ThreadPool .QueueUserWorkI tem(new WaitCallback(Po pulatAdTable));
I have declared my thread method as
static SearchResultCol lection PopulatAdTabe(o bject stateInfo)
{}
Is there something wrong with my declaration? Thanks.
--
Thanks.
"Bruce Wood" wrote:
You use the Join method on the threads. However, there's a small
problem: if you call Join in the UI thread, then you hang the UI.
The usual solution is to use one of the two threads as a "controller ",
or use a third thread. In the first case, the second thread to be
started can be handed a reference to the first thread, and do a Join
before it signals that it's finished. If the first thread isn't
finished yet, then the second thread will wait on the Join until it is.
Therefore, when the second (controller) thread is finished, you know
that they're both finishes.
If the two threads are not logically related this way, then it might be
nicer to use a third, controller thread: the UI starts the controller,
which then starts the two worker threads. The controller then does two
Joins, one on each worker thread, and when the two Joins complete, it
signals the UI that all is done. This is scalable to an arbitrary
number of worker threads.
On Jan 26, 10:35 am, Pucca <P...@discussio ns.microsoft.co mwrote:
Thank you Christof. These 2 threads are started within a form as worker
threads only. They are coded as 2 static method within this form. The 2
threads have no form of its own. How can I then find out when they're both
done with their tasks?
--
Thanks.
"Christof Nordiek" wrote:
Hi Pucca,
the WaitCallBack-handler (PopulateContex tTable e.g.) should signal that at
the and, maybe in a finally block. If this is called from a GUI-Thread you
could call BeginInvoke on one of the Forms methods.
Christof
"Pucca" <P...@discussio ns.microsoft.co mschrieb im Newsbeitrag
>news:E8******* *************** ************@mi crosoft.com...
Hi, I'm using vs2005 and .net 2.0. I started 2 threadpool threads. How
do I
know when they're done with their tasks? Thanks.
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Po pulateContextTa ble));
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Po pulatAdTable));
--
Thanks.- Hide quoted text -- Show quoted text -
I'm using threadpool so I used AutoeventReset and it worked. Thank you very
much.
--
Thanks.
"Bruce Wood" wrote:
You use the Join method on the threads. However, there's a small
problem: if you call Join in the UI thread, then you hang the UI.
The usual solution is to use one of the two threads as a "controller ",
or use a third thread. In the first case, the second thread to be
started can be handed a reference to the first thread, and do a Join
before it signals that it's finished. If the first thread isn't
finished yet, then the second thread will wait on the Join until it is.
Therefore, when the second (controller) thread is finished, you know
that they're both finishes.
If the two threads are not logically related this way, then it might be
nicer to use a third, controller thread: the UI starts the controller,
which then starts the two worker threads. The controller then does two
Joins, one on each worker thread, and when the two Joins complete, it
signals the UI that all is done. This is scalable to an arbitrary
number of worker threads.
On Jan 26, 10:35 am, Pucca <P...@discussio ns.microsoft.co mwrote:
Thank you Christof. These 2 threads are started within a form as worker
threads only. They are coded as 2 static method within this form. The 2
threads have no form of its own. How can I then find out when they're both
done with their tasks?
--
Thanks.
"Christof Nordiek" wrote:
Hi Pucca,
the WaitCallBack-handler (PopulateContex tTable e.g.) should signal that at
the and, maybe in a finally block. If this is called from a GUI-Thread you
could call BeginInvoke on one of the Forms methods.
Christof
"Pucca" <P...@discussio ns.microsoft.co mschrieb im Newsbeitrag
>news:E8******* *************** ************@mi crosoft.com...
Hi, I'm using vs2005 and .net 2.0. I started 2 threadpool threads. How
do I
know when they're done with their tasks? Thanks.
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Po pulateContextTa ble));
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Po pulatAdTable));
--
Thanks.- Hide quoted text -- Show quoted text -
Pucca wrote:
I'm using threadpool so I used AutoeventReset and it worked. Thank you very
much.
Be careful: many uses of AutoResetEvent have a race condition, where the
event is signaled before anything waits on it, thus causing deadlock
when threads do start waiting on it, having "missed the bus", as it
were.
-- Barry
-- http://barrkel.blogspot.com/
AutoResetEvent there is pretty scary. If your "are you done yet?" thread
isn't waiting already, then it's going to miss the fact that your work item
is complete. This means the order you do things in is very important, and
(worse) is also hard to get right.
You would be better served, I suspect, using a ManualResetEven t. This
eliminates the problem, and makes your code less likley to have race
conditions.
--
Chris Mullins, MCSD.NET, MCPD:Enterprise , MVP C# http://www.coversant.net/blogs/cmullins
"Pucca" <Pu***@discussi ons.microsoft.c omwrote in message
news:89******** *************** ***********@mic rosoft.com...
I'm using threadpool so I used AutoeventReset and it worked. Thank you
very
much.
--
Thanks.
"Bruce Wood" wrote:
>You use the Join method on the threads. However, there's a small problem: if you call Join in the UI thread, then you hang the UI.
The usual solution is to use one of the two threads as a "controller ", or use a third thread. In the first case, the second thread to be started can be handed a reference to the first thread, and do a Join before it signals that it's finished. If the first thread isn't finished yet, then the second thread will wait on the Join until it is. Therefore, when the second (controller) thread is finished, you know that they're both finishes.
If the two threads are not logically related this way, then it might be nicer to use a third, controller thread: the UI starts the controller, which then starts the two worker threads. The controller then does two Joins, one on each worker thread, and when the two Joins complete, it signals the UI that all is done. This is scalable to an arbitrary number of worker threads.
On Jan 26, 10:35 am, Pucca <P...@discussio ns.microsoft.co mwrote:
Thank you Christof. These 2 threads are started within a form as
worker
threads only. They are coded as 2 static method within this form. The
2
threads have no form of its own. How can I then find out when they're
both
done with their tasks?
--
Thanks.
"Christof Nordiek" wrote:
Hi Pucca,
the WaitCallBack-handler (PopulateContex tTable e.g.) should signal
that at
the and, maybe in a finally block. If this is called from a
GUI-Thread you
could call BeginInvoke on one of the Forms methods.
Christof
"Pucca" <P...@discussio ns.microsoft.co mschrieb im Newsbeitrag news:E8******* *************** ************@mi crosoft.com...
Hi, I'm using vs2005 and .net 2.0. I started 2 threadpool threads.
How
do I
know when they're done with their tasks? Thanks.
ThreadPool.Queu eUserWorkItem(n ew
WaitCallback(Po pulateContextTa ble));
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Po pulatAdTable));
--
Thanks.- Hide quoted text -- Show quoted text -
I always enjoy seeing how I might do the same thing when using my
concurrency library.
This is actually a pretty common pattern (i.e. scatter/gather). I sample
this pattern here http://www.codeplex.com/PCR/Thread/V...?ThreadId=3459
--
William Stacey [C# MVP]
PCR concurrency library: www.codeplex.com/pcr
PSH Scripts Project www.codeplex.com/psobject
"Pucca" <Pu***@discussi ons.microsoft.c omwrote in message
news:89******** *************** ***********@mic rosoft.com...
| I'm using threadpool so I used AutoeventReset and it worked. Thank you
very
| much.
| --
| Thanks.
|
|
| "Bruce Wood" wrote:
|
| You use the Join method on the threads. However, there's a small
| problem: if you call Join in the UI thread, then you hang the UI.
| >
| The usual solution is to use one of the two threads as a "controller ",
| or use a third thread. In the first case, the second thread to be
| started can be handed a reference to the first thread, and do a Join
| before it signals that it's finished. If the first thread isn't
| finished yet, then the second thread will wait on the Join until it is.
| Therefore, when the second (controller) thread is finished, you know
| that they're both finishes.
| >
| If the two threads are not logically related this way, then it might be
| nicer to use a third, controller thread: the UI starts the controller,
| which then starts the two worker threads. The controller then does two
| Joins, one on each worker thread, and when the two Joins complete, it
| signals the UI that all is done. This is scalable to an arbitrary
| number of worker threads.
| >
| On Jan 26, 10:35 am, Pucca <P...@discussio ns.microsoft.co mwrote:
| Thank you Christof. These 2 threads are started within a form as
worker
| threads only. They are coded as 2 static method within this form.
The 2
| threads have no form of its own. How can I then find out when they're
both
| done with their tasks?
| --
| Thanks.
|
|
|
| "Christof Nordiek" wrote:
| Hi Pucca,
|
| the WaitCallBack-handler (PopulateContex tTable e.g.) should signal
that at
| the and, maybe in a finally block. If this is called from a
GUI-Thread you
| could call BeginInvoke on one of the Forms methods.
|
| Christof
|
| "Pucca" <P...@discussio ns.microsoft.co mschrieb im Newsbeitrag
| >news:E8******* *************** ************@mi crosoft.com...
| Hi, I'm using vs2005 and .net 2.0. I started 2 threadpool
threads. How
| do I
| know when they're done with their tasks? Thanks.
|
| ThreadPool.Queu eUserWorkItem(n ew
WaitCallback(Po pulateContextTa ble));
| ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Po pulatAdTable));
| --
| Thanks.- Hide quoted text -- Show quoted text -
| >
| >
I think the AutoResetEvent is now cuasing a problem for my code.
1. I dind't find good examples on how to code with manualResetEven t, can
you recommend a example on line?
2. Do I need to change my program.cs code's [STAThread] to something else?
Is this the Single thread meaning?
--
Thanks.
"Chris Mullins [MVP]" wrote:
AutoResetEvent there is pretty scary. If your "are you done yet?" thread
isn't waiting already, then it's going to miss the fact that your work item
is complete. This means the order you do things in is very important, and
(worse) is also hard to get right.
You would be better served, I suspect, using a ManualResetEven t. This
eliminates the problem, and makes your code less likley to have race
conditions.
--
Chris Mullins, MCSD.NET, MCPD:Enterprise , MVP C# http://www.coversant.net/blogs/cmullins
"Pucca" <Pu***@discussi ons.microsoft.c omwrote in message
news:89******** *************** ***********@mic rosoft.com...
I'm using threadpool so I used AutoeventReset and it worked. Thank you
very
much.
--
Thanks.
"Bruce Wood" wrote:
You use the Join method on the threads. However, there's a small
problem: if you call Join in the UI thread, then you hang the UI.
The usual solution is to use one of the two threads as a "controller ",
or use a third thread. In the first case, the second thread to be
started can be handed a reference to the first thread, and do a Join
before it signals that it's finished. If the first thread isn't
finished yet, then the second thread will wait on the Join until it is.
Therefore, when the second (controller) thread is finished, you know
that they're both finishes.
If the two threads are not logically related this way, then it might be
nicer to use a third, controller thread: the UI starts the controller,
which then starts the two worker threads. The controller then does two
Joins, one on each worker thread, and when the two Joins complete, it
signals the UI that all is done. This is scalable to an arbitrary
number of worker threads.
On Jan 26, 10:35 am, Pucca <P...@discussio ns.microsoft.co mwrote:
Thank you Christof. These 2 threads are started within a form as
worker
threads only. They are coded as 2 static method within this form. The
2
threads have no form of its own. How can I then find out when they're
both
done with their tasks?
--
Thanks.
"Christof Nordiek" wrote:
Hi Pucca,
the WaitCallBack-handler (PopulateContex tTable e.g.) should signal
that at
the and, maybe in a finally block. If this is called from a
GUI-Thread you
could call BeginInvoke on one of the Forms methods.
Christof
"Pucca" <P...@discussio ns.microsoft.co mschrieb im Newsbeitrag
>news:E8******* *************** ************@mi crosoft.com...
Hi, I'm using vs2005 and .net 2.0. I started 2 threadpool threads.
How
do I
know when they're done with their tasks? Thanks.
ThreadPool.Queu eUserWorkItem(n ew
WaitCallback(Po pulateContextTa ble));
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Po pulatAdTable));
--
Thanks.- Hide quoted text -- Show quoted text -
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: David Jenkins |
last post by:
I have a very small application designed so that the main thread spawns
3 additional threads. All 4 threads then wait for an event from an
Oracle database (message posted on an AQ queue), and are blocked most of
the time. The main thread may be blocked for weeks or months. The 3
spawned threads are much more active, with data to process, objects
created and freed, hourly or more often.
I've found that the application displays symptoms...
|
by: AlexeiOst |
last post by:
Everywhere in documentation there are recommendations to use threads from
thread pooling for relatively short tasks. As I understand, fetching a page
or multiple pages (sometimes up to 50 but not tipical) from the Internet and
doing some processing on those would be considered to be a big/long task for
a thread from a pool. In our app it is possible to break the task into some
small ones (thread per fetch and processing thereafter or event...
|
by: Tpool |
last post by:
hi,
How to create the more than 25 threads in threadpool. i tried more than 25
threads in web request, but it shows an error. how can i have my threads to
some 25 or more ,check the status of the threads, and assigning the task to
completed threads in a loop.
Thanks
|
by: Bryce K. Nielsen |
last post by:
I have an object that starts a thread to do a "process". One of the steps
inside this thread launches 12 other threads via a Delegate.BeginInvoke to
process. After these 12 threads are launched, the main thread waits. At the
completion of each subthread, the mainthread checks all 12 thread objects to
see if they are done. If they are, raise an event that says we're done.
So, it's kinda like this:
ProcessThread
- Creates a ProcessObject
|
by: gel |
last post by:
Hi all
I am attempting to understand threads to use in a network app which I
am writing. The part that I am going to use threads on is run on the
clients/workstations. I will monitor all starting and ending
processes. Below is what I have been doing. It looks like only the
first thread is starting. Can someone explain a basic example of how
threads work and are implemented, what is better to use threading or
thread module, and what am...
| |
by: admin |
last post by:
ok This is my main. Pretty much it goes through each category and
starts up 4 worker threads that then ask for groups to gether from. My
problem is that when the thread gets done it keeps the mysql
connections open so I end up with quite a few at the end. Is there a
different way that I should do this?
class Program
{
static string categories = { "emulation" , "audio" ,
"console" , "anime" , "xxx" , "tv" , "pictures" , "video" };
|
by: =?iso-8859-1?q?Eir=EDkur_Fannar_Torfason?= |
last post by:
I'm wrestling with a problem that I'm hoping someone can help me with.
I have a web application written in VS.2003 and running on version 1.1
of the .NET Framework on XP pro and Windows server 2003 that connects
to a SQL server database and authenticates itself using windows
authentication. The web application is configured to impersonate a
local user account that has been granted access to the database.
Here's the impersonation snip...
|
by: Pinux |
last post by:
Hi,
I am writing a multi-threads encryption application. The idea of the code is to create a number of threads to encrypt files. I have a thread pool say the maximum threads is 10. If the number of tasks (number of files waiting to be encrypted) is larger than the thread pool size, I first create 10 new threads to execute the encryption function. Then I wait for any of the threads to be signaled in the thread pool using WaitForMultipleObjects...
|
by: drtitus7759 |
last post by:
I need a report which will show how many tasks have been completed for each employee and a percent of that based on the total tasks possible.
Example:
Tasks Total Pct
compl tasks Completed
Joe 5 20 25%
Mark 10 20 50%
Steve 5 20 25%
I'm drawing a blank on how to get the 20 for each person.
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |