Hi all,
I basically have a System.Timers.Timer that is set to trigger an event every 10 seconds. In the event, I usedtextbox1.Clear(); so that every time the event is triggered, the textbox clears. Unfortunately, this does not work. I also triedtextbox1.Text = ""; but it still does not work. The textbox is not clearing. Any idea why this happens?
In the beginning of the event, I also wrote this line: myTimer.Enabled = false; to temporarily stop the timer when the event starts. I also wrote this line:myTimer.Enabled = true; just before the event ends to start the timer again. Basically I don't want it to start/trigger the event again while the event is not yet finished executing. Is it okay to do this? or is there a better way to do this?
Here's a snippet of my code:
public partial class Form1 : Form { public Form1() { InitializeComponent(); } System.Timers.Timer myTimer; private void Form1_Load(object sender, EventArgs e) { myTimer = new System.Timers.Timer(); // Create a timer // Tell the timer what to do when it elapses myTimer.Elapsed += new System.Timers.ElapsedEventHandler(someEvent); // Set it to go every 10 seconds for example myTimer.Interval = 10; } private void someEvent(object sender, System.Timers.ElapsedEventArgs e) { myTimer.Enabled = false;
// do stuff here
/////textbox1.Clear();
myTimer.Enabled = true; } }
Please let me know. Thanks
EDIT: I added snippet of my code. I also tested textbox1.Clear(); on a button click event and it works. But it does not work when textbox1.Clear(); is in the event.