An object reference is required to access non-static member

It depends what you're trying to do. You can either make things static, or you can create an instance:

MainClass instance = new MainClass();
btn.Clicked += instance.StartClick;
btn_stop.Clicked += instance.StopClick;

I assume this isn't your real application, so it's hard to say what you should do in your real code. Personally I'd lean towards creating an instance - static variables represent global state which is usually a bad idea (in terms of testability etc). We can't tell whether that affects your situation or not though.

What's important is that you understand why you're getting the error message and why the above change fixes it. Once you understand that, you'll be in a better situation to make the best decisions.


It's because you are accessing non-static methods from the static in this case.

Either create object of the class and than call the method

ObjectOfClass obj = new ObjectOfClass();
obj.MethodName();

so in your case

MainClass obj = new MainClass();
btn.Clicked += obj.StartClick;
btn_stop.Clicked += obj.StopClick;

Or create the called methods as static (which you already tried as you said).