tags:

views:

110

answers:

4

Hi,

I am new to this, did google alot but have confusion. my application has more then 200 threads listing individual devices, now i want to buil GUI for this c++ managed /clr empty project application, where a Form having Grid control, & every thread will update corresponding grip row on events like device open, data transfer & device closed, determine final result is not require so I want fire & forget. with async

plz guide me in detail, with code if possible
should i use control delegates.BeginInvoke or controls' , remember i will call from not UI thread

A: 

200 threads is a lot, the number of threads that your computer can execute at a time is limited by the number of processor cores you have--having extra threads will increase the amount of thread switching, which is a very slow process.

Perhaps you should better describe the general problem (not the specific technical problem) you're trying to solve and see what suggestions you get.

...but to better answer this question... .NET provides several approaches to threading. They typically fall into 2 categories

  • System.Threading.Thread is used to manually manipulate the full lifecycle of individual threads.

  • System.Threading.ThreadPool provides a shared pool of threads which can be used for short jobs, when the thread completes it is returned to the pool. Using the ThreadPool greatly reduces the overhead in creating a new Thread--but the pool is limited, and consuming all threads from it will have severe side effects.

  • In .NET 4.0 there is the concept of a Task, which is not specifically a thread, but provides a mechanism roughly akin to a thread for performing small actions asynchronously

The approach you choose dictates how you work with it. System.Threading.Thread and System.Threading.ThreadStart classes are used for working with threads manually. The ThreadPool's main point of entry is via System.Threading.ThreadPool.QueueNewUserWorkItem(). Delegate.BeginInvoke as well as most methods named "Begin..." use the ThreadPool threads.

STW
A: 

Can I use Delegate.BeginInvoke ? i am not using threadpool (manual).

what I need, is to update gui from managed threads. what is recommended method I am using .net 3.5, any sample code ?

harisali
A: 

From your response, i reckon your using winforms. You can use Control.BeginInvoke or Control.Invoke to invoke into the user interface thread.

From my experience, Winforms BeginInvoke should not be called for 200 threads. The time it takes to update the user interface might be too long and it will cause your user interface to appear to be lag.

Give it a go, but be cautious that the performance of invokes are not good. I would recommend trying to design an architecture where the 200 threads pool the updates and then call Control.Invoke only once, and perform many updates.

Andrew Keith
A: 

thanks, actually 200/ every thread is continously listening individual devices

harisali