Click here to Skip to main content
15,887,854 members
Home / Discussions / C#
   

C#

 
AnswerRe: Writing source code in seperate files PinPopular
Eddy Vluggen28-Jan-12 5:29
professionalEddy Vluggen28-Jan-12 5:29 
GeneralRe: Writing source code in seperate files Pin
PIEBALDconsult28-Jan-12 13:37
mvePIEBALDconsult28-Jan-12 13:37 
AnswerRe: Writing source code in seperate files Pin
BobJanova28-Jan-12 6:32
BobJanova28-Jan-12 6:32 
QuestionSimple MultiThread question Pin
PozzaVecia27-Jan-12 20:51
PozzaVecia27-Jan-12 20:51 
AnswerRe: Simple MultiThread question Pin
OriginalGriff27-Jan-12 21:14
mveOriginalGriff27-Jan-12 21:14 
GeneralRe: Simple MultiThread question Pin
PozzaVecia28-Jan-12 1:21
PozzaVecia28-Jan-12 1:21 
GeneralRe: Simple MultiThread question Pin
OriginalGriff28-Jan-12 2:41
mveOriginalGriff28-Jan-12 2:41 
AnswerRe: Simple MultiThread question Pin
Luc Pattyn27-Jan-12 22:22
sitebuilderLuc Pattyn27-Jan-12 22:22 
Hi,

you don't need the locks you have:

1. Thread.Join() is thread-safe by itself, you adding locks does not help a bit. This is not documented, however it should be obvious as the thread executing the join is doing nothing but wait.

2. Console output is thread-safe also, otherwise Console output would most always be garbled as most apps have several threads. This too is not documented AFAIK.

Locks do make sense when you have one or more methods that:
- want access to the same data;
- AND can be executing at the same time, which implies by different threads.

And even then, for atomic operations, you still wouldn't need a lock (but you may need the volatile keyword). Atomic here means the data operation is performed by a single assembler instruction, e.g. a 32-bit int load or store; a set of atomic items (e.g. a struct) is itself not atomic, so if two ints need to represent a consistent state, then you also would need a lock. When in doubt about atomocity, be safe and use a lock.

And lock objects must be accessible by all methods involved, so a local variable can not serve that purpose. It should be a class member. And for safety, it shouldn't be public: it should be accessible only to the objects that need access.

Smile | :)
Luc Pattyn [My Articles] Nil Volentibus Arduum

Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.

GeneralRe: Simple MultiThread question Pin
PozzaVecia28-Jan-12 1:56
PozzaVecia28-Jan-12 1:56 
AnswerRe: Simple MultiThread question Pin
Luc Pattyn28-Jan-12 2:29
sitebuilderLuc Pattyn28-Jan-12 2:29 
GeneralRe: Simple MultiThread question Pin
harold aptroot28-Jan-12 2:24
harold aptroot28-Jan-12 2:24 
AnswerRe: Simple MultiThread question Pin
Luc Pattyn28-Jan-12 2:50
sitebuilderLuc Pattyn28-Jan-12 2:50 
AnswerRe: Simple MultiThread question Pin
BobJanova28-Jan-12 6:45
BobJanova28-Jan-12 6:45 
GeneralRe: Simple MultiThread question Pin
PozzaVecia28-Jan-12 9:50
PozzaVecia28-Jan-12 9:50 
QuestionConverting MySqlDateTime Pin
Ian_urquhart27-Jan-12 4:50
Ian_urquhart27-Jan-12 4:50 
AnswerRe: Converting MySqlDateTime Pin
Bernhard Hiller27-Jan-12 5:01
Bernhard Hiller27-Jan-12 5:01 
GeneralRe: Converting MySqlDateTime Pin
Ian_urquhart27-Jan-12 5:27
Ian_urquhart27-Jan-12 5:27 
AnswerRe: Converting MySqlDateTime Pin
PIEBALDconsult27-Jan-12 5:08
mvePIEBALDconsult27-Jan-12 5:08 
GeneralRe: Converting MySqlDateTime Pin
Ian_urquhart27-Jan-12 5:31
Ian_urquhart27-Jan-12 5:31 
GeneralRe: Converting MySqlDateTime Pin
Richard Andrew x6427-Jan-12 16:43
professionalRichard Andrew x6427-Jan-12 16:43 
GeneralRe: Converting MySqlDateTime Pin
PIEBALDconsult28-Jan-12 4:03
mvePIEBALDconsult28-Jan-12 4:03 
GeneralRe: Converting MySqlDateTime Pin
jschell28-Jan-12 4:39
jschell28-Jan-12 4:39 
GeneralRe: Converting MySqlDateTime Pin
PIEBALDconsult28-Jan-12 12:05
mvePIEBALDconsult28-Jan-12 12:05 
GeneralRe: Converting MySqlDateTime Pin
jschell28-Jan-12 13:54
jschell28-Jan-12 13:54 
QuestionSocket server handling MySQL queries from clients and return the response to them Pin
Islorvat27-Jan-12 4:48
Islorvat27-Jan-12 4:48 

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.