ThreadTimer plug-in

From NSIS Wiki

Download Link

v1.1.1 (updated 14th, July 2012) by jiake ThreadTimer_v1.1.1.7z (90 KB), with tlibc static library.

v1.1 (updated October 2011) by Slappy (27 KB) Forum thread


ThreadTimer plug-in allows you to create simple Timer which runs in a separate thread. It is available since Start until Stop, it ticks in desired interval and calls NSIS function. It can be created for a whole life-cycle of installer because it is NOT tied with any installer page or nsDialogs page.

I am using this plugin for creating cool-looking Graphical Installers: (see image below)


How To Use

See simple example below for fast start.

ThreadTimer::Start Function

Initializes Timer and starts it immediately. NSIS Function will be called first time Interval milliseconds after calling Start.



This must be defined! Plug-in will crash without this parameter! Note: version 1.1.1 do not need.


Interval for timer [milliseconds]. Timer ticks each Interval and calls NSIS Function.


Number of ticks for Timer. 0 or -1 for infinite loop. (v1.1.1, any value that less than or equal to 0 meant infinite loop).

NSIS Function

Address of NSIS function to call from plug-in. Use GetFunctionAddress to obtain this address of your function.

ThreadTimer::Stop Function

Stops the timer immediately.


Function TryMe
  MessageBox MB_OK "TryMe"
Function TimerExample
  GetFunctionAddress $2 TryMe
  ; Note: version 1.1.1 do not need /NOUNLOAD switch. 
  ThreadTimer::Start /NOUNLOAD 2345 8 $2 ; Timer ticks every 2345 milliseconds, totally 8 times calls TryMe
Function TimerExampleInfiniteLoop
  GetFunctionAddress $2 TryMe
  ; Note: version 1.1.1 do not need /NOUNLOAD switch.
  ThreadTimer::Start /NOUNLOAD 1234 -1 $2 ; Timer ticks every 1234 milliseconds, it calls function TryMe in infinite loop until ThreadTimer::Stop is called
Function .onGUIEnd


There are several important facts to know about this plug-in:

  • Timer runs in separate thread. If you forget to call ThreadTimer::Stop it will still run however your NSIS installer exists! This may cause (and often causes) crash!
  • There is no error handling in this version, be careful with parameters!
  • If you need to execute some function periodically in whole life of installer (on each page, also while installing files, ...) use ThreadTimer::Start in your .onInit function.
  • It is nice habit to call ThreadTimer::Stop in your .onGUIEnd function.
  • Plug-in does not use SetTimer and KillTimer WinAPI functions. Instead it creates a new thread and uses Sleep() to wait for desired Interval. There might be a little inaccuracy in time periods!

Versions History

1.1.1 (July 2012)(by jiake)
  • Update it so that you can remove /NOUNLOAD switch when using in NSIS
  • Remove unused code from source
  • Size 3.5kB(ANSI)/3kB(Unicode)

1.1 (October 2011)
  • Second version
  • Unicode & ANSI builds are available
  • Sources included
  • Pure C code - removed all dependencies on CRT but included TinyC lib
  • Removed decorated names of calls
  • Size ~4kB

1.0 (2011)
  • First version
  • Unicode & ANSI builds are available
  • Sources included
  • Removed dependency on MS VCR 9.0 runtime (Bigger size of dll).


Personal tools