See Also: How to enable a timer from a different thread/class
The timer is assigned to a form and I’d like to Enable it at a specific location,but from another class.I don’t want to make it public
This is the code I use to access memo
public string TextValue { set { if (this.Memo.InvokeRequired) { this.Invoke((MethodInvoker)delegate { this.Memo.Text += value + '\n'; }); } else { this.Memo.Text += value + '\n'; } } } public static void addtxt(string txt) { var form = Form.ActiveForm as Form1; if(form != null) form.TextValue = txt; }
How would you like to enable the timer ? What action is undertaken in order to enable it ?
Is it possible to add an event to the class from which you want to enable the timer, and, on the form which contains the timer, subscribe to that event ? In the event-handler for that event, you can then enable the timer.
When the other class raises the event, the eventhandler will enable the timer.
Something like this. (I haven’t tested, nor did I even compile it, but I think you’ll catch the drift 🙂 ).