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

C#

 
AnswerRe: WPF toolkit DataGrid and DataSet Pin
Richard Andrew x6417-May-10 14:09
professionalRichard Andrew x6417-May-10 14:09 
Questionwat's wrong ? Pin
igalep13217-May-10 10:07
igalep13217-May-10 10:07 
AnswerRe: wat's wrong ? Pin
Not Active17-May-10 11:07
mentorNot Active17-May-10 11:07 
QuestionMessage Removed Pin
17-May-10 10:02
professionalN_tro_P17-May-10 10:02 
AnswerRe: Nullable Type or On the fly calculations Pin
Dr.Walt Fair, PE17-May-10 10:34
professionalDr.Walt Fair, PE17-May-10 10:34 
AnswerRe: Nullable Type or On the fly calculations Pin
Richard MacCutchan17-May-10 10:35
mveRichard MacCutchan17-May-10 10:35 
AnswerRe: Nullable Type or On the fly calculations Pin
Luc Pattyn17-May-10 11:18
sitebuilderLuc Pattyn17-May-10 11:18 
QuestionThreads and TextBox Pin
CaesarCZ17-May-10 9:53
CaesarCZ17-May-10 9:53 
Hi, still getting to know C# and recently stumbled upon a problem I'm not sure about.

I have two threads, each of them updating a WinForm's TextBox. I'm using the usual InvokeRequired:

if (this.OutputConsole.InvokeRequired)
{
   this.OutputConsole.Invoke(
      new OutputConsoleUpdater(delegate(string s) { this.OutputConsole.AppendText(s + "\r\n"); }),
      text
   );
}
else
{
    this.OutputConsole.AppendText(text + "\r\n");
}


But bad things happened when I tried to add some sort of locking to that Unsure | :~ o. I just added a lock around the above mentioned code

lock(ConsoleLock)
{
   // the snippet from above
}


A deadlock occured, the thread that actually needs the Invoke gets the lock ("user thread"), and tries to call Invoke, "delegating" the code to the thread that created the control ("original thread"). The original thread, though, wants to write something to the TextBox too, and is stuck waiting for the lock, currently held by the user thread, which in turn keeps waiting for the original thread to process the delegated call. So far, so good.

The question is: if I remove the lock, why does it still work okay... is the TextBox, in some way, thread-safe? Is it due to the way the Invoke call works (and if so, how does it work in the first place)? I don't really see how I could make it work using locks anyway (as long as I have to use the above mentioned paradigm), do you see how it could be done?

thanks for your time Smile | :) !
AnswerRe: Threads and TextBox Pin
Not Active17-May-10 9:59
mentorNot Active17-May-10 9:59 
GeneralRe: Threads and TextBox Pin
CaesarCZ17-May-10 10:25
CaesarCZ17-May-10 10:25 
AnswerRe: Threads and TextBox Pin
Luc Pattyn17-May-10 10:03
sitebuilderLuc Pattyn17-May-10 10:03 
GeneralRe: Threads and TextBox Pin
CaesarCZ17-May-10 10:21
CaesarCZ17-May-10 10:21 
GeneralRe: Threads and TextBox Pin
Luc Pattyn17-May-10 11:08
sitebuilderLuc Pattyn17-May-10 11:08 
GeneralRe: Threads and TextBox Pin
CaesarCZ18-May-10 2:28
CaesarCZ18-May-10 2:28 
Questionimage access using dll Pin
AnirbanChak 17-May-10 9:52
AnirbanChak 17-May-10 9:52 
AnswerRe: image access using dll Pin
Dr.Walt Fair, PE17-May-10 10:20
professionalDr.Walt Fair, PE17-May-10 10:20 
AnswerRe: image access using dll Pin
Alan Balkany18-May-10 4:18
Alan Balkany18-May-10 4:18 
QuestionJava to C# Pin
Zoomlion17-May-10 6:46
Zoomlion17-May-10 6:46 
GeneralRe: Java to C# Pin
harold aptroot17-May-10 7:04
harold aptroot17-May-10 7:04 
AnswerRe: Java to C# Pin
The Man from U.N.C.L.E.17-May-10 7:28
The Man from U.N.C.L.E.17-May-10 7:28 
Questionequivalent Pin
genieabdo17-May-10 4:52
genieabdo17-May-10 4:52 
AnswerRe: equivalent Pin
Abhinav S17-May-10 5:01
Abhinav S17-May-10 5:01 
AnswerRe: equivalent Pin
Luc Pattyn17-May-10 5:37
sitebuilderLuc Pattyn17-May-10 5:37 
GeneralRe: equivalent Pin
genieabdo17-May-10 5:57
genieabdo17-May-10 5:57 
GeneralRe: equivalent Pin
Luc Pattyn17-May-10 6:05
sitebuilderLuc Pattyn17-May-10 6:05 

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.