Click here to Skip to main content
15,913,722 members
Home / Discussions / C#
   

C#

 
GeneralRe: Save Text as Image Pin
D i x y19-Feb-08 18:44
D i x y19-Feb-08 18:44 
Generalreferencing dlls with same name. Pin
D2raghu19-Feb-08 17:08
D2raghu19-Feb-08 17:08 
GeneralRe: referencing dlls with same name. Pin
Hamza Nadim20-Feb-08 5:00
Hamza Nadim20-Feb-08 5:00 
GeneralGAC related question Pin
Imtiaz Murtaza19-Feb-08 13:24
Imtiaz Murtaza19-Feb-08 13:24 
GeneralRe: GAC related question Pin
Luc Pattyn19-Feb-08 13:56
sitebuilderLuc Pattyn19-Feb-08 13:56 
GeneralRe: GAC related question Pin
PIEBALDconsult19-Feb-08 14:04
mvePIEBALDconsult19-Feb-08 14:04 
QuestionThread instance object location Pin
Spacix One19-Feb-08 13:01
Spacix One19-Feb-08 13:01 
GeneralRe: Thread instance object location Pin
Luc Pattyn19-Feb-08 14:25
sitebuilderLuc Pattyn19-Feb-08 14:25 
Hi,

I have several comments on your code:

1.
identifiers are case-sensitive, but having two variables differ in casing only is a bad idea, so I do
not recommend your line i=I;. For one, you will confuse yourself, and furthermore if you
read this aloud to someone, he won't understand you at all.
Remark: nevertheless, people often have properties and local values that differ only by the casing of
their first letter, so you could have public int Something {set {something=value;}}
which is generally accepted and understood by everyone.

2.
I don't like the newThread names (both namespace and class) very much. Everything is new at first, and
gets old by itself, so I would avoid having new in such names. I would suggest "MyThread", "TestThread",
"SomeSpecialThreadDoingSoAndSo", whatever best describes it.
It may seem irrelevant, but picking appropriate names will help you as soon as you (or a team of people)
get involved in bigger projects, so I recommend taking care of this from day one.

3.
The line Thread.Sleep(1); will not behave exactly as you expect, it will typically sleep for 10 or
more milliseconds; you may want to read my timers article.

4.
To answer your specific question: the sequence
- call constructor (mainForm = new winFormApp)
- set some properties (mainForm.newThread =)
- now call a method to start something happening (Application.Run(mainForm)
is quite common, and in fact it is most often better than using a constructor or a method with a lot of
parameters.
However, I don't particularly like the idea of passing a thread to some class.
If the class is about a thread experiment, I would put all the thread related code inside the class, it
does not help having half of it in the class, and half outside.
If the class needs a thread for its own purposes (making the thread irrelevant to the outside), I would
definitely put all the thread stuff inside).

5.
I didn't like the newThreadID = new Thread(...); line much, i.e. the variable's name
should be newThread, not newThreadID, since it really is a thread (a threadID is a number identifying
a thread at the kernel level, a Thread is an instance of the Thread class).

6.
In general it is not a good idea to kill/abort a thread; it is a drastic measure to terminate it immediately,
with the disadvantage that it potentially leaves its objects in an unknown state (files open, resources
locked, whatever). So it should be avoided if possible. Here the intent seems to be to allow the app
to exit, which any foreground thread would prevent. The solution is to make it a background thread,
hence newThread.IsBackground=true; before newThread.Start();
Doing so will cause Windows to kill the background threads as soon as all foreground threads are done,
so there too the object states may be indetermined, but at exit this is of lesser importance, since
Windows will always try and clean up at exit too.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.


GeneralRe: Thread instance object location Pin
Spacix One19-Feb-08 17:08
Spacix One19-Feb-08 17:08 
GeneralRe: Thread instance object location Pin
Luc Pattyn20-Feb-08 4:07
sitebuilderLuc Pattyn20-Feb-08 4:07 
GeneralReflectively setting properties on value types Pin
Skippums19-Feb-08 12:06
Skippums19-Feb-08 12:06 
AnswerRe: Reflectively setting properties on value types Pin
Skippums19-Feb-08 12:25
Skippums19-Feb-08 12:25 
GeneralRe: Reflectively setting properties on value types Pin
PIEBALDconsult19-Feb-08 13:13
mvePIEBALDconsult19-Feb-08 13:13 
GeneralRe: Reflectively setting properties on value types Pin
PIEBALDconsult19-Feb-08 13:06
mvePIEBALDconsult19-Feb-08 13:06 
GeneralRe: Reflectively setting properties on value types Pin
Skippums20-Feb-08 6:46
Skippums20-Feb-08 6:46 
Questionp-port output problem Pin
Gunnar575919-Feb-08 11:25
Gunnar575919-Feb-08 11:25 
GeneralRe: p-port output problem Pin
Christian Graus19-Feb-08 12:32
protectorChristian Graus19-Feb-08 12:32 
QuestionData table in C# Pin
dalbhide bipin19-Feb-08 11:12
dalbhide bipin19-Feb-08 11:12 
GeneralRe: Data table in C# Pin
Gareth H19-Feb-08 11:35
Gareth H19-Feb-08 11:35 
GeneralRe: Data table in C# Pin
dalbhide bipin19-Feb-08 18:47
dalbhide bipin19-Feb-08 18:47 
GeneralArray null problem Pin
netJP12L19-Feb-08 10:58
netJP12L19-Feb-08 10:58 
GeneralRe: Array null problem Pin
Ravi Bhavnani19-Feb-08 11:03
professionalRavi Bhavnani19-Feb-08 11:03 
GeneralRe: Array null problem Pin
TheGreatAndPowerfulOz20-Feb-08 13:32
TheGreatAndPowerfulOz20-Feb-08 13:32 
Questionhow to create web site blocker Pin
Mahmood Abbasi19-Feb-08 10:06
Mahmood Abbasi19-Feb-08 10:06 
AnswerRe: how to create web site blocker Pin
Ravi Bhavnani19-Feb-08 10:45
professionalRavi Bhavnani19-Feb-08 10:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.