It looks like you are calling a non static member (a property or method, specifically setTextboxText
) from a static method (specifically SumData
). You will need to either:
- Make the called member static also:
static void setTextboxText(int result) { // Write static logic for setTextboxText. // This may require a static singleton instance of Form1. }
- Create an instance of
Form1
within the calling method:private static void SumData(object state) { int result = 0; //int[] icount = (int[])state; int icount = (int)state; for (int i = icount; i > 0; i--) { result += i; System.Threading.Thread.Sleep(1000); } Form1 frm1 = new Form1(); frm1.setTextboxText(result); }
Passing in an instance ofForm1
would be an option also. - Make the calling method a non-static instance method (of
Form1
):private void SumData(object state) { int result = 0; //int[] icount = (int[])state; int icount = (int)state; for (int i = icount; i > 0; i--) { result += i; System.Threading.Thread.Sleep(1000); } setTextboxText(result); }
More info about this error can be found on MSDN.