473,394 Members | 1,867 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,394 software developers and data experts.

creating threads

Can someone please break down a simple statement for a relative newbie?

Expand|Select|Wrap|Line Numbers
  1. Thread firstThread = new Thread (new ThreadStart (Method1));
In other words, what is happening at each stage here:

Expand|Select|Wrap|Line Numbers
  1. new ThreadStart (Method1)
Expand|Select|Wrap|Line Numbers
  1. new Thread (new ThreadStart (Method1))
Expand|Select|Wrap|Line Numbers
  1. Thread firstThread = new Thread (new ThreadStart (Method1));
Thanks for any help you can give.
Jul 17 '09 #1
1 1315
IanWright
179 100+
I'd recommend MSDN for things such as this, but here's a summary for you.

Expand|Select|Wrap|Line Numbers
  1. new ThreadStart (Method1)
  2.  
A Thread needs somewhere to start, which obviously will be a Method. Normally this will be
a parameterless method with no return. e.g.
Expand|Select|Wrap|Line Numbers
  1. private void DoStuff()
Overall we call this starting point a ThreadStart, and we pass in a method to the constructor.

Expand|Select|Wrap|Line Numbers
  1. new Thread (new ThreadStart (Method1))
This simply takes what we had before 1 step further. We are now constructing a new Thread, and passing
a ThreadStart to the constructor (which in this case is being constructed on the same line of code). This
tells the Thread whereabouts it should start.

Expand|Select|Wrap|Line Numbers
  1. Thread firstThread = new Thread (new ThreadStart (Method1));
You're now taking it further by saving a reference to your Thread in a parameter called firstThread so you
can then refer to it later.
Jul 20 '09 #2

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

Similar topics

0
by: Randall Smith | last post by:
I was doing some testing with Python threads and found that when I try to create 300 threads one immediately after another, the 255th thread can't be created. The error message I get is: ...
4
by: Ajay | last post by:
hi! i have an application that runs on a pocket pc. the application has a server which responds to UDP requests. each request contains the address of another server (say, server_b). the pocket...
6
by: Christian Buckl | last post by:
Hi, I try to implement my own thread class based on POSIX threads. I want my class to manage everything (creation of threads, exception handling...). This includes also some functions that need to...
1
by: David Pratt | last post by:
Hi. I am running a zope server. Zope runs 4 threads and I have a document processing method that can require minutes to run so I do not want to run out of threads. A solution to this is to run...
5
by: Adam Clauss | last post by:
I am creating a plugin for MS Outlook. Upon clicking a toolbar button, I create series of threads (variable number each time). Within each thread, I start a form using Application.Run(...). This...
5
by: Bob Bins | last post by:
Is there a way to create a shared lock using the Monitor class or any other synchronization class in .NET? So I have one resource that may have multiple threads using it at once but a second...
12
by: David Beoulve | last post by:
In my windows C# app, I create a thread to separate the main code block from the GUI, which recursively sorts through all the directories starting from a given point, and every time it finds a...
5
by: dk60 | last post by:
Here is a problem I encountered concerning threads: Here is the code in Form1 button click handler: AddForm addForm = new AddForm(booksDataSet.Titles); Thread addTitleThread=new Thread(new...
5
by: indianteam | last post by:
I have a scenario where I need to do multiple things and the flow is not synchronous. I need one thread to be listening to a socket using the recv socket api. Other thread to be sending some...
9
by: =?Utf-8?B?YmJn?= | last post by:
Hi all, I read somewhere "using kernel stuff in thread is not good.." if ManualResetEvent object is created in thread but not actually used, will it affect performance? Bob
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...

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.