Click here to Skip to main content
15,891,529 members
Home / Discussions / C#
   

C#

 
QuestionSending email goes to bulk folder Pin
DannyAdler24-Mar-06 1:53
DannyAdler24-Mar-06 1:53 
QuestionHow to use lock in C# Pin
Bob_Sun24-Mar-06 1:17
Bob_Sun24-Mar-06 1:17 
AnswerRe: How to use lock in C# Pin
leppie24-Mar-06 1:40
leppie24-Mar-06 1:40 
GeneralRe: How to use lock in C# Pin
Bob_Sun24-Mar-06 4:54
Bob_Sun24-Mar-06 4:54 
GeneralRe: How to use lock in C# Pin
Guffa24-Mar-06 1:44
Guffa24-Mar-06 1:44 
GeneralRe: How to use lock in C# Pin
Bob_Sun24-Mar-06 4:48
Bob_Sun24-Mar-06 4:48 
GeneralRe: How to use lock in C# Pin
Guffa24-Mar-06 4:57
Guffa24-Mar-06 4:57 
GeneralRe: How to use lock in C# Pin
Bob_Sun24-Mar-06 5:39
Bob_Sun24-Mar-06 5:39 
Thank you very much.
I have read your following reply.

Who told you that it wasn't a good way, and what was the arguments for that?

I was just told so, and I found the following forum.
http://msdn.microsoft.com/msdnmag/issues/03/01/NET/[^]

Locking should of course be kept as a minimum, and to avoid deadlocks a thread should never lock more than one object at a time. Still, for sharing data between threads there is hardly any alternative.  

I wrote a class for statemachine, whenever a event is dispatched, the whole statemachine should be locked in the thread. As for number of objects locked in this thread, it is always more than 2. As this is a statemachine, state changes must be sent to upper class. As the so called upper class collects messages from many child classes, messages are first enqueued before processed.
So, in this thread

lock(this)    // Statemachine<br />
{<br />
    ...<br />
    lock(this)    // MessageQueue<br />
    {<br />
        ...<br />
    }<br />
}


When several events occured in different threads, I suppose all of them will be locked at the first
lock(this) // Statemachine

before processed. Will this cause a deadlock in my program ?
AnswerRe: How to use lock in C# Pin
Guffa24-Mar-06 6:42
Guffa24-Mar-06 6:42 
GeneralRe: How to use lock in C# Pin
Bob_Sun24-Mar-06 6:54
Bob_Sun24-Mar-06 6:54 
AnswerRe: How to use lock in C# Pin
Steve Hansen24-Mar-06 1:58
Steve Hansen24-Mar-06 1:58 
GeneralRe: How to use lock in C# Pin
Bob_Sun24-Mar-06 5:11
Bob_Sun24-Mar-06 5:11 
GeneralRe: How to use lock in C# Pin
Steve Hansen24-Mar-06 6:16
Steve Hansen24-Mar-06 6:16 
QuestionDG-&gt;GridView problem... Pin
E.L. Golpe24-Mar-06 1:05
E.L. Golpe24-Mar-06 1:05 
QuestionAbout lock Pin
Bob_Sun24-Mar-06 0:47
Bob_Sun24-Mar-06 0:47 
AnswerRe: About lock Pin
Guffa24-Mar-06 2:03
Guffa24-Mar-06 2:03 
QuestionAcceptTcpClient() Pin
albCode24-Mar-06 0:35
albCode24-Mar-06 0:35 
AnswerRe: AcceptTcpClient() Pin
Ed.Poore24-Mar-06 7:46
Ed.Poore24-Mar-06 7:46 
AnswerRe: AcceptTcpClient() Pin
HakunaMatada24-Mar-06 22:36
HakunaMatada24-Mar-06 22:36 
QuestionOleDbConnection Problem... Pin
Jax_qqq24-Mar-06 0:10
Jax_qqq24-Mar-06 0:10 
AnswerRe: OleDbConnection Problem... Pin
E.L. Golpe24-Mar-06 2:43
E.L. Golpe24-Mar-06 2:43 
GeneralRe: OleDbConnection Problem... Pin
Jax_qqq26-Mar-06 21:59
Jax_qqq26-Mar-06 21:59 
QuestionShow/Hide Quick Launch Bar Pin
sherwani23-Mar-06 23:57
sherwani23-Mar-06 23:57 
AnswerRe: Show/Hide Quick Launch Bar Pin
leppie24-Mar-06 1:41
leppie24-Mar-06 1:41 
QuestionHow to load text.. Pin
AeQuitaZ23-Mar-06 23:34
AeQuitaZ23-Mar-06 23:34 

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.