mattdrinks
Technical User
Is this possible...
I have an event that is fired by a timer, but I would like that event to update a form as it goes so the user can see what is happening.
I have the following code:
But I can not access the form from inside the OnTimedEvent Method becuase it is static.
eg.
will not work.
does anyone have any ideas how I can achieve this.
Thanks for your help,
Matt
P.S. I am using Dot Net 2.0 (Beta 2)
I have an event that is fired by a timer, but I would like that event to update a form as it goes so the user can see what is happening.
I have the following code:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Timers;
namespace SendingAgent
{
public partial class Form1 : Form
{
public static System.Timers.Timer aTimer = new System.Timers.Timer();
public Form1()
{
InitializeComponent();
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
// Set the Interval to 2.5 seconds (2500 milliseconds).
aTimer.Interval = 2500;
aTimer.Enabled = false;
}
// Specify what you want to happen when the Elapsed event is
// raised.
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
MessageBox.Show("Hello World!");
}
private void btnStart_Click(object sender, EventArgs e)
{
Form1.aTimer.Enabled = true;
}
private void btnStop_Click(object sender, EventArgs e)
{
Form1.aTimer.Enabled = false;
}
}
}
But I can not access the form from inside the OnTimedEvent Method becuase it is static.
eg.
Code:
Form1.txtStatus.Text = "Started..."
does anyone have any ideas how I can achieve this.
Thanks for your help,
Matt
P.S. I am using Dot Net 2.0 (Beta 2)