Auto refresh inside windows form
Team ,
We are using windows form c#. Is there any library for auto refresh (need to few logic every 1 min. Please see the attachment ) . ? These setting is within the app.
Thanks
Shiv
9 Replies
this should suffice.
Also this aint outlook bro 🤣
Thanks @Dharmang . It is working . Can we stop this ?
try timer.Dispose()
No timer.Dispose() is not working. It keeps on triggering every 10 secs @Dharmang
share the code
private async void checkBox2_CheckedChanged(object sender, EventArgs e)
{
var timer = new PeriodicTimer(TimeSpan.FromSeconds(10));
if (checkBox2.Checked == true)
{
while (await timer.WaitForNextTickAsync())
{
MessageBox.Show("Triggered");
}
}
else
{
timer.Dispose();
} } it is inside checkbox checked event inside windows form
} } it is inside checkbox checked event inside windows form
can you also share the xaml code
this is winui3 code but similar
OK let me try this
public PeriodicTimer timer = new PeriodicTimer(TimeSpan.FromSeconds(3));
Should this code go inside constructer?
We need to trigger it somewhere right?
timer.Dispose(); worked if I move this outside the checkbox changed event
public PeriodicTimer timer = new PeriodicTimer(TimeSpan.FromSeconds(3));
but again it wont start if i enable it . public partial class Form1 : Form { PeriodicTimer timer; public Form1() { InitializeComponent(); } private async void checkBox1_CheckedChanged(object sender, EventArgs e) { if (checkBox1.Checked == true) { timer = new PeriodicTimer(TimeSpan.FromSeconds(5)); while (await timer.WaitForNextTickAsync()) { MessageBox.Show("Triggered"); } } else { timer.Dispose(); } } } this worked ... there is no CheckBox_Unchecked in windows form so i am checking inside the main check changed event
but again it wont start if i enable it . public partial class Form1 : Form { PeriodicTimer timer; public Form1() { InitializeComponent(); } private async void checkBox1_CheckedChanged(object sender, EventArgs e) { if (checkBox1.Checked == true) { timer = new PeriodicTimer(TimeSpan.FromSeconds(5)); while (await timer.WaitForNextTickAsync()) { MessageBox.Show("Triggered"); } } else { timer.Dispose(); } } } this worked ... there is no CheckBox_Unchecked in windows form so i am checking inside the main check changed event
ya this would work
maybe dispose absolutely clears the initiated object