I want to do something like this in C# (more specifically, WPF):
Thread.Invoke(MyCallback, 1000);
Which will just call MyCallback, 1 time, 1 second from now.
What is the easiest way to do this with .NET? Do I have to setup a Timer and hook an event?
You can use System.Timers.Timer to do this without spawning your own thread. Implement the Elapsed callback to do what you want, setting Enabled
true and AutoReset
false to achieve a single invocation.
Make sure you Dispose
the Timer
object once you are done with it!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With