C
C#

Auto refresh inside windows form

Auto refresh inside windows form

SShiv11/21/2023
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
No description
DDharmang11/21/2023
this should suffice.
var timer = new PeriodicTimer(TimeSpan.FromSeconds(10));

while (await timer.WaitForNextTickAsync())
{
Console.WriteLine("Hello World after 10 seconds")
}
var timer = new PeriodicTimer(TimeSpan.FromSeconds(10));

while (await timer.WaitForNextTickAsync())
{
Console.WriteLine("Hello World after 10 seconds")
}
Also this aint outlook bro 🤣
SShiv11/21/2023
Thanks @Dharmang . It is working . Can we stop this ?
DDharmang11/21/2023
try timer.Dispose()
SShiv11/21/2023
No timer.Dispose() is not working. It keeps on triggering every 10 secs @Dharmang
DDharmang11/21/2023
share the code
SShiv11/21/2023
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
DDharmang11/21/2023
can you also share the xaml code
public PeriodicTimer timer = new PeriodicTimer(TimeSpan.FromSeconds(3));

private async void CheckBox_Checked(object sender, RoutedEventArgs e)
{
while (await timer.WaitForNextTickAsync())
{
Debug.WriteLine("triggered");
}
}

private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
{
timer.Dispose();
}
public PeriodicTimer timer = new PeriodicTimer(TimeSpan.FromSeconds(3));

private async void CheckBox_Checked(object sender, RoutedEventArgs e)
{
while (await timer.WaitForNextTickAsync())
{
Debug.WriteLine("triggered");
}
}

private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
{
timer.Dispose();
}
this is winui3 code but similar
SShiv11/21/2023
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
DDharmang11/21/2023
ya this would work maybe dispose absolutely clears the initiated object

Looking for more? Join the community!

C
C#

Auto refresh inside windows form

Join Server
Want results from more Discord servers?
Add your server
Recommended Posts
✅ Fresh Install of Windows, I'm Getting Weird Errors (NETSDK1/NU1012, and DEP0700)Anyone know what might be happening here in my Maui Blazor Hybrid projects? For the older project object reference not set to instance of object on a static method callso im trying to use an opengl binding package (Veldrid.OpenGLBinding) but, when i call any of the meWeb API model classesI'm coding a webshop using ASP.NET Core Web API for the backend and Next.js for the frontend. I'm deInvalidate JWT-Tokens on logout and password change.I have an ASP.net Web api that handles user interaction. For authentification I use JWT Tokens. I reDynamically enable/disable a route in ASP.NET 7?Is there a way to dynamically enable/disable a route in ASP.NET 7? I'd like to be able to enable/dis✅ I keep getting Error CS5001 and CS0028, how do i get rid of themin CS5001 it says Program does not contain a static "Main" method suitable for an entry point and inStruct with explicit layoutHi, I am using Wintab and I am trying to make packet struct, but I have some problem. In some situatExtending custom WPF controlWhat are my options to extend this TimePicker list element to full height that shows all items? I'm Discord.Net + MagicOnion, hehehHey! So I am working on a discord bot that I want to intergrate into a server using websockets, I fA question for my c# winforms projecthello guys, i have a question about my c# winforms project. So : I have 2 Projects the first ProjecYO I NEED HELP writing a code need advice not for u to write it for mewrite me a c# program that get 3 latters and tell if they are by the order like abc if they are backBlazor ServicesI dont know too much blazor, but I have a .cs file in a /Settings folder, in which I would like to aHow to optimize this?I have following: ```cs using System; namespace SquareCalculus { internal class FigureTriangle In VSCode, SDK not Recognized on ChromeOSHi. I just installed the .NET SDK and the Runtime by following the instructions for Ubuntu on the MiNito.AsyncEx vs DotNext.ThreadingWe're currently searching for a nice AsyncAutoResetEvent implementation. We found two suitable impleSequential BlinkersHello everyone! I bought these sequential blinkers that run off an stm32 blue pill board. the only pTrying to use Microsoft.Kiota namespace but not found when importingI am trying to use this method from the Microsoft.Kiota.Abstractions.Extensions namespace: ToFirstChWinUI3 Scheduler CalendarViewhello im trying to make a winui3 calendarview interactive calendar where I can predefine dates in myThe call is ambiguous between the following methods or properties: 'Thread.Thread(ThreadStart)' andi have to upload by filesHelp a noobie out with a simple hangmanHi! New to coding and I need some help to solve this problem. Shall I save the words to a list? Any