Click here to Skip to main content
15,909,651 members
Home / Discussions / C#
   

C#

 
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 
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 
Sorry, my reply wasn't very accurate; I should have payed more attention to the details of your code. The way I do such things typically is like so:
public void SetText(Control control, string text) {
    if (control.InvokeRequired) {
        control.Invoke(new ControlStringConsumer(SetText), new object[]{control, text});  // invoking itself
    } else {
        control.Text=text;      // the "functional part", executing only on the main thread
    }
}


and then my earlier reply would apply. My "canonical form" as I call it here[^], has the advantage of containing the actual operation code only once.

Your code, which was
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");
}


could be simplified to
this.OutputConsole.Invoke(
   new OutputConsoleUpdater(delegate(string s) { this.OutputConsole.AppendText(s + "\r\n"); }),
   text);

assuming we are NOT on the GUI thread. Using Invoke() it also causes the delegate to be executed on the GUI thread, through Windows messages, implying an automatic sequential treatment.

Now I'm not sure about the lock issue you raised; it may depend on where exactly you put it, and even more on what is inside the OutputConsoleUpdater constructor. But anyway, the conclusion will be there is no need for such a lock.

FWIW: you could break the automatic sequencing by using Application.DoEvents() inside some event handler; that is exactly why doing so is a very bad idea most of the time.

Smile | :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]

I only read formatted code with indentation, so please use PRE tags for code snippets.

I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).

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 
AnswerRe: equivalent Pin
PIEBALDconsult17-May-10 6:05
mvePIEBALDconsult17-May-10 6:05 
GeneralRe: equivalent Pin
genieabdo17-May-10 6:11
genieabdo17-May-10 6:11 
GeneralRe: equivalent Pin
Luc Pattyn17-May-10 6:12
sitebuilderLuc Pattyn17-May-10 6:12 
GeneralRe: equivalent Pin
genieabdo17-May-10 6:23
genieabdo17-May-10 6:23 
GeneralRe: equivalent Pin
PIEBALDconsult17-May-10 6:24
mvePIEBALDconsult17-May-10 6:24 

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.