ThreadTimer plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(Created page with "== Download Link == v1.0 by Slappy <attach>ThreadTimer-v1.0.zip</attach> [http://forums.winamp.com/showthread.php?t=331275 Forum thread] == Description == Thread...")
 
Line 68: Line 68:
* Unicode & ANSI builds are available
* Unicode & ANSI builds are available
* Sources included
* Sources included
* Removed dependency on MS VCR 9.0 runtime (Bigger size of dll).


== Credits ==
== Credits ==
*Version 1.0 by [[User:Slappy|Slappy]] Graphical installers: [http://www.unsigned-softworks.sk www.unsigned-softworks.sk]
*Version 1.0 by [[User:Slappy|Slappy]] Graphical installers: [http://www.unsigned-softworks.sk www.unsigned-softworks.sk]
[[Category:Plugins]]
[[Category:Plugins]]

Revision as of 13:50, 8 June 2011

Download Link

v1.0 by Slappy ThreadTimer-v1.0.zip (68 KB) Forum thread

Description

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: www.unsigned-softworks.sk/installer (see image below)

SkinnedControls-Example.jpg

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.

Parameters

/NOUNLOAD

This must be defined! Plug-in will crash without this parameter!

Interval

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

Ticks

Number of ticks for Timer. 0 or -1 for 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.


Example

Function TryMe
  MessageBox MB_OK "TryMe"
FunctionEnd
 
Function TimerExample
  GetFunctionAddress $2 TryMe
  ThreadTimer::Start /NOUNLOAD 2345 8 $2 ; Timer ticks every 2345 milliseconds, totally 8 times calls TryMe
FunctionEnd
 
Function .onGUIEnd
	ThreadTimer::Stop
FunctionEnd

Notes

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.0 (2011)
  • First version
  • Unicode & ANSI builds are available
  • Sources included
  • Removed dependency on MS VCR 9.0 runtime (Bigger size of dll).

Credits