Click here to Skip to main content
15,890,512 members
Home / Discussions / C#
   

C#

 
AnswerRe: Strange windows forms control bug? Pin
simplefolk25-Aug-11 3:45
simplefolk25-Aug-11 3:45 
Questionthread safety Pin
CodingYoshi24-Aug-11 11:52
CodingYoshi24-Aug-11 11:52 
AnswerRe: thread safety Pin
SledgeHammer0124-Aug-11 12:10
SledgeHammer0124-Aug-11 12:10 
GeneralRe: thread safety Pin
CodingYoshi24-Aug-11 16:24
CodingYoshi24-Aug-11 16:24 
AnswerRe: thread safety PinPopular
Luc Pattyn24-Aug-11 12:10
sitebuilderLuc Pattyn24-Aug-11 12:10 
GeneralRe: thread safety Pin
AspDotNetDev24-Aug-11 12:18
protectorAspDotNetDev24-Aug-11 12:18 
GeneralRe: thread safety Pin
CodingYoshi24-Aug-11 16:44
CodingYoshi24-Aug-11 16:44 
GeneralRe: thread safety PinPopular
Luc Pattyn24-Aug-11 17:16
sitebuilderLuc Pattyn24-Aug-11 17:16 
the terminology may be a little confusing, this is how I explain it:

1.
every instance of lock(lock-object), all sharing the same lock-object, restricts access to whatever code is inside the lock's code block, in such a way that only one thread can get passed the lock-block's entry point. Once a thread has succeeded entering such code block, all other threads trying to enter the same lock-block (or some other lock-block on the same lock-object) will be stalled until the former leaves its lock-block, and only then one of the others is allowed to proceed.

2.
So the lock-object is like a key that fits every lock statement that refers to it; the key is unique, there is only one of it (for a given lock-object), and initially it is available to everyone; the first thread to reach a lock statement grabs the key, and can proceed; he must relinquish the key when leaving the lock-block; in the mean time the other threads, encountering a lock, would have to wait for the key to become available.

3.
locks only make sense when you have more than one thread (warning: a lot of asynchronous events, such as a network's DataReceived, would execute on different threads).

4.
using locks correctly isn't easy for the novice; with too much locking, you may cripple the app's performance and the user experience, ultimately the app could come to a halt ("dead-lock"). With insufficient locking all may seem fine, until suddenly weird things start to happen, e.g. wrong results getting generated as some object gets into an unexpected state, when one thread changes one state variable, while another thread changes another, resulting in some inconsistencies.

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

GeneralRe: thread safety Pin
CodingYoshi25-Aug-11 3:28
CodingYoshi25-Aug-11 3:28 
AnswerRe: thread safety Pin
Luc Pattyn25-Aug-11 3:38
sitebuilderLuc Pattyn25-Aug-11 3:38 
AnswerRe: thread safety Pin
AspDotNetDev24-Aug-11 12:17
protectorAspDotNetDev24-Aug-11 12:17 
AnswerRe: thread safety Pin
PIEBALDconsult24-Aug-11 17:42
mvePIEBALDconsult24-Aug-11 17:42 
AnswerRe: thread safety Pin
jschell25-Aug-11 8:41
jschell25-Aug-11 8:41 
GeneralRe: thread safety Pin
CodingYoshi25-Aug-11 15:01
CodingYoshi25-Aug-11 15:01 
GeneralRe: thread safety Pin
jschell26-Aug-11 8:28
jschell26-Aug-11 8:28 
QuestionWhat is the best way to make application Multi Language ? Pin
Honeyboy_2024-Aug-11 11:15
Honeyboy_2024-Aug-11 11:15 
JokeRe: What is the best way to make application Multi Language ? Pin
PIEBALDconsult24-Aug-11 14:56
mvePIEBALDconsult24-Aug-11 14:56 
GeneralRe: What is the best way to make application Multi Language ? Pin
Subin Mavunkal25-Aug-11 1:48
Subin Mavunkal25-Aug-11 1:48 
GeneralRe: What is the best way to make application Multi Language ? Pin
PIEBALDconsult25-Aug-11 2:43
mvePIEBALDconsult25-Aug-11 2:43 
AnswerRe: What is the best way to make application Multi Language ? Pin
simplefolk25-Aug-11 3:51
simplefolk25-Aug-11 3:51 
AnswerRe: What is the best way to make application Multi Language ? Pin
Bernhard Hiller25-Aug-11 5:05
Bernhard Hiller25-Aug-11 5:05 
Questionhow to convert my C# winform program to service program ? Pin
Gali197824-Aug-11 6:53
Gali197824-Aug-11 6:53 
AnswerRe: how to convert my C# winform program to service program ? Pin
Hari Om Prakash Sharma24-Aug-11 7:15
Hari Om Prakash Sharma24-Aug-11 7:15 
AnswerRe: how to convert my C# winform program to service program ? Pin
#realJSOP24-Aug-11 8:01
mve#realJSOP24-Aug-11 8:01 
QuestionProblem in work with ocx file Pin
SajjadZare24-Aug-11 5:08
SajjadZare24-Aug-11 5:08 

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.