Member1

Member1

  • NA
  • 169
  • 48.7k

object reference cannot set to the instance of object?

Jul 15 2015 2:35 AM
I have one method called "Appendtxtdata(string value)". in form1.cs and i want to use it in another class abc.cs for write text. i used following code but doesnt work. 
Thanku. 

in form1.cs.

public void AppendTxtdata(string value)
{
try
{
if (InvokeRequired)
{
this.Invoke(new Action<string>(AppendTxtdata), new object[] { value });
return;
}
txtdata.Text += value;
}
catch { }
}

in abc.cs

public void getdata() // to run server //
{
Form1  f = new Form1();
f.AppendTxtdata("data sent");
}

the getdata method calling in another method and that method is called in form1 in thread.


Answers (29)