I have a UI Class with StatusBarPanels
Then I have another Class that is a thread.
I want this class thread to update the StatusBarPanels in the UI class.
But I get the error:
error CS0120: An object reference is required for the nonstatic field,
method, or property myNameSpace.MainForm.SetStatusBarText(string)'
Please help a old C# newbie...
Short version:
public class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.StatusBarPanel statusBarPanel1;
private System.Windows.Forms.StatusBarPanel statusBarPanel2;
private System.Windows.Forms.StatusBarPanel statusBarPanel3;
private void MainForm_Load(object sender, System.EventArgs e)
{
thread1= new MyThread();
}
public void SetStatusBarText(string txt)
{
if (InvokeRequired)
{
BeginInvoke(new StringParameterDelegate(SetVekt1StatusBarText), new
object[]{txt});
return;
}
this.statusBarPanel1.Text = txt;
}
}
public class MyThread
{
Thread myThread;
public MyThread()
{
ThreadStart threadEntry= new ThreadStart(this.beginThread);
myThread= new Thread(threadEntry);
myThread.Start();
}
public void beginComliThread()
{
int a=0;
while(true)
{
Thread.Sleep(500);
MainForm.SetStatusBarText(++a);
}