I am writing a small application for reminders. For this, I got great help from a similar question and answer on Stack Overflow. I used the code mentioned by Thunder from here.
The relevant code is:
private void Form1_Load(object sender, EventArgs e)
{
System.Threading.TimerCallback callback = new System.Threading.TimerCallback(ProcessTimerEvent);
var dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day , 10, 0, 0);
if (DateTime.Now < dt)
{
var timer = new System.Threading.Timer(callback, null, dt - DateTime.Now, TimeSpan.FromHours(24));
this.Hide(); // This line works... Form hides itself
}
}
private void ProcessTimerEvent(object obj)
{
//MessageBox.Show("Hi Its Time");
this.Show(); //This line does not work. Form gets disposed off instead of show
}
My problem: I get everything as mentioned in that answer (including MessageBox). However, if I try to hide the form when a callback is made and show it once again instead of MessageBox.Show("Hi Its Time")
it does not work. See my comments on each line. I don't understand why the form gets disposed.
this.Visible() // does not work and disposed off the same way
Also tried to move the form out of screen by changing its location property. On return, bring back to its original location but this also does not work. What can I do to hide & show the form on return ?