473,508 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# threads array

1 New Member
Hi,

I'm traying to make a thread array to a function with one variable, but i get everytime an error. I trayed to put the variable by the call, but the compiler doen't like that too.



Expand|Select|Wrap|Line Numbers
  1. static void Main(string[] args)
  2. {
  3. Thread[] threads = new Thread[5];
  4.  
  5. for(int i = 0; i < threads.Length; i++)
  6. {
  7. threads[i] = new Thread(new ThreadStart(DoWork));
  8. }
  9.  
  10. for(int i = 0; i < threads.Length; i++)
  11. {
  12. threads[i].Start();
  13. }
  14.  
  15. for(int i = 0; i < threads.Length; i++)
  16. {
  17. threads[i].Join();
  18. }
  19.  
  20. Console.WriteLine("Complete");
  21. }
  22.  
  23. public void DoWork(String myStr)
  24. {
  25. Console.WriteLine("DoWork"+myStr);
  26. }
Aug 24 '08 #1
1 2740
DonBytes
25 New Member
Expand|Select|Wrap|Line Numbers
  1. static void Main(string[] args)
  2.         {
  3.             Thread[] threads = new Thread[5];
  4.  
  5.             for (int i = 0; i < threads.Length; i++)
  6.             {
  7.                 threads[i] = new Thread(new ParameterizedThreadStart(DoWork));
  8.             }
  9.  
  10.             for (int i = 0; i < threads.Length; i++)
  11.             {
  12.                 threads[i].Start(i.ToString()); // or whatever you want to send to your thread
  13.             }
  14.  
  15.             for (int i = 0; i < threads.Length; i++)
  16.             {
  17.                 threads[i].Join();
  18.             }
  19.  
  20.             Console.WriteLine("Complete");
  21.             Console.ReadKey();
  22.         }
  23.  
  24.         public static void DoWork(Object StringObject)
  25.         {
  26.             String myStr = (StringObject as String);
  27.             Console.WriteLine(String.Format("{0} DoWork", myStr));
  28.         }
Aug 24 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4092
by: Dennis Gavrilov | last post by:
Hi, All! I have two questions: strategic and technical. Technical one first: I need to share an array of objects (implemented as hashes, having references to other objects and hashes, sharing...
6
2735
by: Max Adams | last post by:
Threads and ThreadPool's If I use a ThreadPool how can I tell when a thead in the threadpool has exited? I don't want to set a global member variable I would much rather be able to act on an...
9
2350
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...
3
22152
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...
11
1434
by: mareal | last post by:
I am trying to write a basic load balancer (in our web service) solution. The purpose of this load balancer is to keep an array updated with server status. We have several servers that can be...
10
1735
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...
7
3090
by: Michael | last post by:
I'm writing an application that decodes a file containing binary records. Each record is a particular event type. Each record is translated into ASCII and then written to a file. Each file contains...
4
1572
by: chelfter | last post by:
I need to synchronize all the threads to add all the numbers. Threads are created, but not started immediately. When the threads do start, they must start simultaneously, without preferential...
1
1615
by: DR | last post by:
what are the memory caps for threads running as a CLR stored procedure executed by sql server 2005? is it limited by OS only or also by sql servers memory limits? e.g. lets say my clr stored...
5
1451
by: Antoninus Twink | last post by:
On 25 May 2008 at 20:15, Aggelidis Nikos wrote: There's a good reason for that. If a variable with automatic storage could be accessed by any thread, when would you suggest it gets destroyed? ...
0
7229
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
7129
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
7333
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
7502
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...
1
5057
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
4716
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...
0
3208
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
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1566
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.