Reputation: 3020
I have a form (Form1) and this form has a System.Timers.Timer
object. I'd like to Invalidate the form (Basically this is my goal, to Invalidate (call Invalidate()
) the form every once in a while where timeout period changes each time when event is triggered). However since event handler method is static, I don't have access to instance of my form.
How can I pass some objects to my event handler?
Upvotes: 0
Views: 2416
Reputation: 37632
I am pretty sure you can use MS TPL. Start from here
Task formManager;
private void FormManagerUpdateUI()
{
// ... UI update work here ...
}
private void StartFormManager()
{
formManager = Task.Factory.StartNew(() => { /* You validation code goes here */ }, TaskCreationOptions.LongRunning);
formManager.ContinueWith((t) => { FormManagerUpdateUI(); }, TaskScheduler.FromCurrentSynchronizationContext());
}
Upvotes: 1
Reputation: 671
This is pretty simple, the winforms timer is a component which means you can drag and drop a timer onto your form. Use the properties grid to enable the time and set the timer interval. Change the property grid to display the events and double click the tick event. A new event handler will be created for you.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
Invalidate();
}
}
Upvotes: 1