To try to get a mental grasp on threading, I tried monkey-see-monkey-do, and copied (like read and type, not cut and paste) from THIS_PAGE on MSDN.
When I did that, I got the following errors
Error 2 The type or namespace name 'SetTextCallback' could not be found (are you missing a using directive or an assembly reference?) Form1.cs 385 17 ZYX987
Error 3 The type or namespace name 'SetTextCallback' could not be found (are you missing a using directive or an assembly reference?) Form1.cs 385 41 ZYX987
I scrolled down aways on the web page and found a lot of community comments indicating that everyone has the exact same problem because the example is misleading. i.e., SetTextCallback
is never declared.
This is the copycat version I typed while staring at the MSDN page...
private void SetText(string text)
{
// InvokeRequired required compares the thread ID of
// the calling thread to the thread ID of the
// creating thread. If these threads are different,
// it returns true
if (this.label1.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
this.label1.Text = text;
}
}
Would someone here please suggest where I should place SetTextCallback
in my CopyCatCode ?
Second question: what does the syntax for declaring it look like ?
Third question: if SetTextCallback
is a method, then what should be in it ?
I searched for "...SetTextCallback ..." (no quotes) here on Stack Overflow and found a few references, but not this exact problem. Hope this is the kind of question that belongs here. Thanks for reading.
Scroll down in the msdn page you linked to ("How to: Make Thread-Safe Calls to Windows Forms Controls"), the full source is listed at the bottom. You'll find there the definition:
// This delegate enables asynchronous calls for setting
// the text property on a TextBox control.
delegate void SetTextCallback(string text);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With