Event Handler Calling Invoke prop.

  • Thread starter Thread starter moelsayed
  • Start date Start date
M

moelsayed

Guest
Hello Everyone,


I am pretty new in suing C# and I am countering some troubles.

I have created a windows form application and during initialization windows form will call a class inside this class I am triggering a timer till this here everything is working well.

but I am trying to populate the time in textbox by invoking the text property but I am getting an error [ check to determine if the object is null before calling method )


the code as in below:

public class scn
{
public delegate void fm();
private int o = 0;
Form1 f = (Form1)Application.OpenForms["Form1"];
Timer _myTimer;
public void fun()
{

_myTimer = new Timer();
_myTimer.Interval = 5000;
_myTimer.Tick += _myTimer_Tick;
_myTimer.Start();


}

void _myTimer_Tick(object sender, EventArgs e)
{
o++;
MessageBox.Show(o.ToString());
funmnreq();


}



public void funmn()
{
f.textBox2.Text = o.ToString();
}
public void funmnreq()
{
f.textBox2.Invoke(new fm(funmn)); // here is the error is happening
}

}


Thanks

Moelsayed

Continue reading...
 
Back
Top