Re: Thread-Save WinForm GET calls
- From: abc <newsgroups101@xxxxxxxxx>
- Date: 31 May 2007 19:14:41 -0700
On May 28, 10:41 pm, burlo <b...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
In your GetText method when InvokRequired is true it does not return a
string as defined by the delegate. The invoke function needs to return a
value. See below.
private string GetText()
{
if (this.textBox1.InvokeRequired)
{
GetTextCallback d = new GetTextCallback(GetText);
object returnedCallBackObject= this.Invoke(d, new object[] {});
return (string)returnedCallBackObject;
}
else
{
return this.textBox1.Text;
}
}
"abc" wrote:
I have been following all the example about how to SET a form element
property in athread-safemanner (see SET example below), but I can
not find any examples about how toGETa form element property in a
thread-safemanner. I tried using the code in theGETsection below,
but I got the error message "not all code paths return a value". I
don't really know what I am doing. Please help.
######### SET #########
delegate void SetTextCallback(string text);
private void ThreadProcSafe()
{
// this function has been called on a newthread
this.SetText("This text was set safely.");
}
private void SetText(string text)
{
if (this.textBox1.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
this.textBox1.Text = text;
}
}
#########GET#########
delegate string GetTextCallback();
private void ThreadProcSafe()
{
// this function has been called on a newthread
string s = this.GetText();
}
private string GetText()
{
if (this.textBox1.InvokeRequired)
{
GetTextCallback d = new GetTextCallback(GetText);
this.Invoke(d, new object[] { });
}
else
{
return this.textBox1.Text;
}
}- Hide quoted text -
- Show quoted text -
that works well.
Thanks a million
.
- Prev by Date: Re: Dynamic SQL instead of stored procs?
- Next by Date: Re: add new user to file agent please
- Previous by thread: Re: Dynamic SQL instead of stored procs?
- Next by thread: Re: add new user to file agent please
- Index(es):
Relevant Pages
|
|