cross thread
-
Hi, How can I make a safe cross thread call for a textbox to set the 'text' of the textbox?
-
something like:
if(this.txt1.InvokeRequiered){
Invoke(new MethodInvoker(delegate
{
this.txt1.Text = ComputedValue();
}));Something like that. [Edit]This example assumes that you created your working thread from the UI thread[/Edit]
modified on Sunday, February 28, 2010 12:50 PM
-
something like:
if(this.txt1.InvokeRequiered){
Invoke(new MethodInvoker(delegate
{
this.txt1.Text = ComputedValue();
}));Something like that. [Edit]This example assumes that you created your working thread from the UI thread[/Edit]
modified on Sunday, February 28, 2010 12:50 PM
You can either disable cross thread exception or you can use delegates. My advice, use delegates! :) Cheer's, Alex Manolescu.
-
I do pretty much the same as Moshu except I invoke the method again from within the method if required (recursion) and repass the parameters rather than hardcoding them.
private void SetText(Control control, string text)
{
if (InvokeRequired)
Invoke(new MethodInvoker(delegate { SetText(textBox, text); }));
else
control.Text = text;
}Dave
Tip: Passing values between objects using events (C#)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
I do pretty much the same as Moshu except I invoke the method again from within the method if required (recursion) and repass the parameters rather than hardcoding them.
private void SetText(Control control, string text)
{
if (InvokeRequired)
Invoke(new MethodInvoker(delegate { SetText(textBox, text); }));
else
control.Text = text;
}Dave
Tip: Passing values between objects using events (C#)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
You can either disable cross thread exception or you can use delegates. My advice, use delegates! :) Cheer's, Alex Manolescu.
Nice to here of you again. Now romanian stuff. Ce mai zici? N-ai m-ai raspuns. In ce parti ale tarii esti? Oras. In ce domeniu(specific) lucri? Back to english => I'm working on a
System.Terror
implementaion. Would anyone like to help me in my effort? It curently implements theISpanihInquistion
,LiquidNitrogen
,AbsDoDoubtlyNitro
and many many others such asIDoublyDoubtAnything
,ISuck
,IPlz
,IWantFerrari
and so on. [Edit] And of course**IForgatToMention**
that**IAmInsane**
. [/edit] cheersmodified on Sunday, February 28, 2010 1:36 PM
-
Hi, How do you make the control enter that method? Shouldn't there be some sort of callback declared?
However you like, you can call that method from a callback if desired. If you are wanting to handle an event from a different thread without calling another method then just match up to the event signature as you do in your event handler to invoke the handler on the correct thread.
Dave
Tip: Passing values between objects using events (C#)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
Hi, How can I make a safe cross thread call for a textbox to set the 'text' of the textbox?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
-
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
-
Nice to here of you again. Now romanian stuff. Ce mai zici? N-ai m-ai raspuns. In ce parti ale tarii esti? Oras. In ce domeniu(specific) lucri? Back to english => I'm working on a
System.Terror
implementaion. Would anyone like to help me in my effort? It curently implements theISpanihInquistion
,LiquidNitrogen
,AbsDoDoubtlyNitro
and many many others such asIDoublyDoubtAnything
,ISuck
,IPlz
,IWantFerrari
and so on. [Edit] And of course**IForgatToMention**
that**IAmInsane**
. [/edit] cheersmodified on Sunday, February 28, 2010 1:36 PM
Hi Mosule, i've been busy with my work :) i'll send you a pm. cheers