In my multi-threaded applications, I need to access cross-threads in user interface elements, and I use safe-flow methods to do this. I use this many times in many of my projects and save them in a form file so that the file looks ugly. So I want to create a seprate class where I can put all this and call them when necessary, but I am having problems with it. For instace to change the text element of the control I use the following
delegate void SetTextCallback(string text, Control ctrl);
public void SetText(string text, Control ctrl)
{
if (ctrl.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text, ctrl });
}
else
{
if (ctrl.GetType() == typeof(Label))
{
ctrl.Text = text;
}
else
{
ctrl.Text += Environment.NewLine + text;
}
}
}
and call this function as
SetText("some text",label1);
This works fine if it is in a form class, if I put it in another class, I get an error in the line
this.Invoke(d, new object[] { text, ctrl });
- , .
, , , , , , , . -
public void ChangePropert(Control ctrl,Property prop,Value val)