How to call system.threading.timer on same thread?

user4648576

Everytime I switch something on my form, I restart my thread by doing (to call whatever was switched):

Retriever.Dispose();
Retriever = new System.Threading.Timer(CallPictureBoxRetriever, null, 0, 300000);

The problem is that this is yet creating another thread and closing the previous!

I am asking how can I call CallPictureBoxRetriever(Object state) on the same thread created so therefore I do not have to always dispose/recreate a thread; rather have 1 thread.

RagtimeWilly

Just reset the timer:

Retriever.Change(0, 300000); // reset to 300 seconds

First argument is dueTime:

Specify zero (0) to restart the timer immediately.

Second is period:

The time interval between invocations of the callback method specified when the Timer was constructed, in milliseconds. Specify Timeout.Infinite to disable periodic signaling.

Full docs here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

System.Timers.Timer vs System.Threading.Timer

From Dev

System.Threading.Timer callback is never called

From Dev

Is it bad practice to recursively call a thread method (System.Threading)?

From Dev

Thread-safety of System.Timers.Timer vs System.Threading.Timer

From Dev

Why using System.Threading.Thread.Sleep() is a bad practice?

From Dev

C# Winforms System.Threading.Timer

From Dev

Python threading -- How to know if thread already is running?

From Dev

Pass System.Threading.Timer object reference to its callback function

From Dev

System.Threading.Timer vs System.Threading.Thread.Sleep resolution - .NET Timer not using system clock resolution

From Dev

Error: Excepiton in System.Threading.ThreadAbortException: Thread was being aborted

From Dev

System.Threading.Timer stops the thread?

From Dev

System.Threading.Thread.Sleep(1000) vs. System.Threading.Tasks.Task.Delay(1000).Wait()

From Dev

How can a one-shot System.Threading.Timer dispose itself?

From Dev

How Python threading Timer work internally?

From Dev

Timer doesn't contain in System.Threading at Xamarin.Forms

From Dev

Does threading.Timer open a function in a separate thread?

From Dev

.NET Core 1.0 equivalent for System.Threading.Thread.CurrentThread.ManagedThreadId

From Dev

System.Threading.Timer low level implementation

From Dev

Is it bad practice to recursively call a thread method (System.Threading)?

From Dev

Python threading -- How to know if thread already is running?

From Dev

System.Threading.Timer vs System.Threading.Thread.Sleep resolution - .NET Timer not using system clock resolution

From Dev

Replace Thread.Sleep with System.Threading.Timer?

From Dev

System.Threading.Timer Calling an Implicit Duplicate of a Callback Function?

From Dev

Countdown timer in a thread using System.Timers.Timer

From Dev

Why can't I use CapturePhotoToStreamAsync from a System.Threading.Timer call back in WPF?

From Dev

How to preserve System.Threading.Timer when function is call again

From Dev

System.Threading.Timer won't work constantly

From Dev

What happens when I use System.Threading.Timer with TimerTrigger?

From Dev

How can I get an equivalent of Python threading.Timer that uses system uptime?

Related Related

  1. 1

    System.Timers.Timer vs System.Threading.Timer

  2. 2

    System.Threading.Timer callback is never called

  3. 3

    Is it bad practice to recursively call a thread method (System.Threading)?

  4. 4

    Thread-safety of System.Timers.Timer vs System.Threading.Timer

  5. 5

    Why using System.Threading.Thread.Sleep() is a bad practice?

  6. 6

    C# Winforms System.Threading.Timer

  7. 7

    Python threading -- How to know if thread already is running?

  8. 8

    Pass System.Threading.Timer object reference to its callback function

  9. 9

    System.Threading.Timer vs System.Threading.Thread.Sleep resolution - .NET Timer not using system clock resolution

  10. 10

    Error: Excepiton in System.Threading.ThreadAbortException: Thread was being aborted

  11. 11

    System.Threading.Timer stops the thread?

  12. 12

    System.Threading.Thread.Sleep(1000) vs. System.Threading.Tasks.Task.Delay(1000).Wait()

  13. 13

    How can a one-shot System.Threading.Timer dispose itself?

  14. 14

    How Python threading Timer work internally?

  15. 15

    Timer doesn't contain in System.Threading at Xamarin.Forms

  16. 16

    Does threading.Timer open a function in a separate thread?

  17. 17

    .NET Core 1.0 equivalent for System.Threading.Thread.CurrentThread.ManagedThreadId

  18. 18

    System.Threading.Timer low level implementation

  19. 19

    Is it bad practice to recursively call a thread method (System.Threading)?

  20. 20

    Python threading -- How to know if thread already is running?

  21. 21

    System.Threading.Timer vs System.Threading.Thread.Sleep resolution - .NET Timer not using system clock resolution

  22. 22

    Replace Thread.Sleep with System.Threading.Timer?

  23. 23

    System.Threading.Timer Calling an Implicit Duplicate of a Callback Function?

  24. 24

    Countdown timer in a thread using System.Timers.Timer

  25. 25

    Why can't I use CapturePhotoToStreamAsync from a System.Threading.Timer call back in WPF?

  26. 26

    How to preserve System.Threading.Timer when function is call again

  27. 27

    System.Threading.Timer won't work constantly

  28. 28

    What happens when I use System.Threading.Timer with TimerTrigger?

  29. 29

    How can I get an equivalent of Python threading.Timer that uses system uptime?

HotTag

Archive