Skip to content
⌘ NSIS Forum Archive

Problem With Timer And ProgressBar

5 posts

r2du-soft#

Problem With Timer And ProgressBar

i create a progressbar for show change a sideshow
but when i use from sleep,timer It also stops! I don't wanna sleep effect on the timer process....

Example1:
after open run,if click on install button the progressbar too sleeping!
i want sleep, Without affecting the timer

!include "mui2.nsh"

Page Custom My_Custom_Page_Show My_Custom_Page_Leave
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English


Var Label
Var ProgressBar
Var ProgressBar_Counter
Var BMP_SlideShow
Var SlideShow_Type
Var Dialog

Section

SectionEnd


Function My_Custom_Page_Show

nsDialogs::Create 1018
Pop $Dialog
${IF} $Dialog == error
  Abort
${EndIF}

##-----------------------------------------------
${NSD_CreateLabel} 50 30 50 14 ""
Pop $Label
#------------------------------------------------

##-----------------------------------------------
${NSD_CreateProgressBar} 50 50 80% 20 ""
Pop $ProgressBar
StrCpy $ProgressBar_Counter 100
SendMessage $ProgressBar ${PBM_SETPOS} $ProgressBar_Counter 0
EnableWindow $ProgressBar 0
#------------------------------------------------

##-----------------------------------------------
${NSD_CreateBitmap} 50 80 100% 100% ""
Pop $BMP_SlideShow
EnableWindow $BMP_SlideShow 0
${NSD_SetImage} $BMP_SlideShow "$EXEDIR\a.bmp" $0
StrCpy $SlideShow_Type "a.bmp"
#------------------------------------------------


##-----------------------------------------------
${NSD_CreateTimer} ProgressBarPRO.Callback 10
#------------------------------------------------



nsDialogs::Show

FunctionEnd


Function ProgressBarPRO.Callback

${IF} $SlideShow_Type S== "a.bmp"
		IntOp $ProgressBar_Counter $ProgressBar_Counter - 1
		SendMessage $ProgressBar ${PBM_SETPOS} $ProgressBar_Counter 0
		${IF} $ProgressBar_Counter S== 0
				StrCpy $ProgressBar_Counter 100
				SendMessage $ProgressBar ${PBM_SETPOS} $ProgressBar_Counter 0
				${NSD_SetImage} $BMP_SlideShow "$EXEDIR\b.bmp" $0
				StrCpy $SlideShow_Type "b.bmp"
		${EndIF}
${ElseIF} $SlideShow_Type S== "b.bmp"
		IntOp $ProgressBar_Counter $ProgressBar_Counter - 1
		SendMessage $ProgressBar ${PBM_SETPOS} $ProgressBar_Counter 0
		${IF} $ProgressBar_Counter S== 0
				StrCpy $ProgressBar_Counter 100
				SendMessage $ProgressBar ${PBM_SETPOS} $ProgressBar_Counter 0
				${NSD_SetImage} $BMP_SlideShow "$EXEDIR\a.bmp" $0
				StrCpy $SlideShow_Type "a.bmp"
		${EndIF}
${EndIF}
FunctionEnd


Function My_Custom_Page_Leave
StrCpy $0 0
BCK:
IntOp $0 $0 + 1
${NSD_SETTEXT} $Label "Sleep $0 Sec"
${IF} $0 <= 3
Sleep 1000
Goto BCK
${Else}
	;MessageBox MB_OK "3"
	${NSD_SETTEXT} $Label ""
${ENDIF}
Abort
FunctionEnd


Example2:

also in this example,sleep affecting on the timer!
!include "mui2.nsh"

Page Custom My_Custom_Page_Show ;My_Custom_Page_Leave
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English


Var Label
Var ProgressBar
Var ProgressBar_Counter
Var BMP_SlideShow
Var SlideShow_Type
Var Dialog

Section

SectionEnd


Function My_Custom_Page_Show

nsDialogs::Create 1018
Pop $Dialog
${IF} $Dialog == error
  Abort
${EndIF}

##-----------------------------------------------
${NSD_CreateLabel} 50 30 50 14 ""
Pop $Label
#------------------------------------------------

##-----------------------------------------------
${NSD_CreateProgressBar} 50 50 80% 20 ""
Pop $ProgressBar
StrCpy $ProgressBar_Counter 100
SendMessage $ProgressBar ${PBM_SETPOS} $ProgressBar_Counter 0
EnableWindow $ProgressBar 0
#------------------------------------------------


##-----------------------------------------------
${NSD_CreateBitmap} 50 80 100% 100% ""
Pop $BMP_SlideShow
EnableWindow $BMP_SlideShow 0
${NSD_SetImage} $BMP_SlideShow "$EXEDIR\a.bmp" $0
StrCpy $SlideShow_Type "a.bmp"
#------------------------------------------------


##-----------------------------------------------
${NSD_CreateTimer} Sleep.Callback 10
#------------------------------------------------


##-----------------------------------------------
${NSD_CreateTimer} ProgressBarPRO.Callback 10
#------------------------------------------------








nsDialogs::Show

FunctionEnd


Function ProgressBarPRO.Callback

${IF} $SlideShow_Type S== "a.bmp"
		IntOp $ProgressBar_Counter $ProgressBar_Counter - 1
		SendMessage $ProgressBar ${PBM_SETPOS} $ProgressBar_Counter 0
		${IF} $ProgressBar_Counter S== 0
				StrCpy $ProgressBar_Counter 100
				SendMessage $ProgressBar ${PBM_SETPOS} $ProgressBar_Counter 0
				${NSD_SetImage} $BMP_SlideShow "$EXEDIR\b.bmp" $0
				StrCpy $SlideShow_Type "b.bmp"
		${EndIF}
${ElseIF} $SlideShow_Type S== "b.bmp"
		IntOp $ProgressBar_Counter $ProgressBar_Counter - 1
		SendMessage $ProgressBar ${PBM_SETPOS} $ProgressBar_Counter 0
		${IF} $ProgressBar_Counter S== 0
				StrCpy $ProgressBar_Counter 100
				SendMessage $ProgressBar ${PBM_SETPOS} $ProgressBar_Counter 0
				${NSD_SetImage} $BMP_SlideShow "$EXEDIR\a.bmp" $0
				StrCpy $SlideShow_Type "a.bmp"
		${EndIF}
${EndIF}
		
FunctionEnd


Function Sleep.Callback
${NSD_KillTimer} Sleep.Callback
StrCpy $0 0
BCK:
IntOp $0 $0 + 1
${NSD_SETTEXT} $Label "Sleep $0 Sec"
${IF} $0 <= 3
Sleep 1000
Goto BCK
${Else}
	;MessageBox MB_OK "3"
	${NSD_SETTEXT} $Label ""
	
	${NSD_CreateTimer} Sleep.Callback 10
	
${ENDIF}
FunctionEnd
r2du-soft#
!include MUI2.nsh 
 
 
Page Custom MY_TEST
!insertmacro MUI_LANGUAGE "English" 

Var ProgressBar_1_Without_Delay
Var ProgressBar_2_With_Delay

Var int_1
Var int_2

Function MY_TEST

nsDialogs::Create 1018

##-----------------------------------------------
${NSD_CreateProgressBar} 10 20 430 30 ""
Pop $ProgressBar_1_Without_Delay
#------------------------------------------------

##-----------------------------------------------
${NSD_CreateProgressBar} 10 80 430 30 ""
Pop $ProgressBar_2_With_Delay
#------------------------------------------------

##-----------------------------------------------
GetFunctionAddress $0 ProgressBar_1_Without_Delay.CallBack
ThreadTimer::Start 1 -1 $0
#------------------------------------------------

##-----------------------------------------------
${NSD_CreateTimer} ProgressBar_2_With_Delay.CallBack 1
#------------------------------------------------

nsDialogs::Show
FunctionEnd

Function ProgressBar_1_Without_Delay.CallBack
IntOp $int_1 $int_1 + 1
SendMessage $ProgressBar_1_Without_Delay ${PBM_SETPOS} $int_1 0
FunctionEnd



Function ProgressBar_2_With_Delay.CallBack
IntOp $int_2 $int_2 + 1
SendMessage $ProgressBar_2_With_Delay ${PBM_SETPOS} $int_2 0
Sleep 3333
FunctionEnd


Section 

SectionEnd  

in this example To avoid slowing down the display of changes What can i do?
So that the Sleep 3333 Does not change the $ProgressBar_1_Without_Delay display speed?????
r2du-soft#
thanks Anders
The way you said is not working in some cases
now i use from the ${NSD_CreateTimer} wait for waiting but in loops the SlideShow Timer Stoppen!

See This Example:


!include "mui2.nsh"

Page Custom My_Custom_Page_Show
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English


Var Label
Var ProgressBar
Var ProgressBar_Counter
Var BMP_SlideShow
Var SlideShow_Type
Var Dialog

Section

SectionEnd


Function My_Custom_Page_Show

nsDialogs::Create 1018
Pop $Dialog
${IF} $Dialog == error
  Abort
${EndIF}

##-----------------------------------------------
${NSD_CreateLabel} 50 30 50 14 ""
Pop $Label
#------------------------------------------------

##-----------------------------------------------
${NSD_CreateProgressBar} 50 50 80% 20 ""
Pop $ProgressBar
StrCpy $ProgressBar_Counter 100
SendMessage $ProgressBar ${PBM_SETPOS} $ProgressBar_Counter 0
EnableWindow $ProgressBar 0
#------------------------------------------------

##-----------------------------------------------
${NSD_CreateBitmap} 50 80 100% 100% ""
Pop $BMP_SlideShow
EnableWindow $BMP_SlideShow 0
${NSD_SetImage} $BMP_SlideShow "$EXEDIR\a.bmp" $0
StrCpy $SlideShow_Type "a.bmp"
#------------------------------------------------


##-----------------------------------------------
GetFunctionAddress $0 ProgressBarPRO.Callback
ThreadTimer::Start 10 -1 $0
#------------------------------------------------

##-----------------------------------------------
${NSD_CreateTimer} Do_IT_Works.CallBack 5000
#------------------------------------------------


nsDialogs::Show
FunctionEnd



Function Do_IT_Works.CallBack
${NSD_KillTimer} Do_IT_Works.CallBack
Call Looper
FunctionEnd



Function Looper
RET:
IntOp $R0 $R0 + 1
${NSD_SETTEXT} $Label $R0
Goto RET
FunctionEnd

Function ProgressBarPRO.Callback
${IF} $SlideShow_Type S== "a.bmp"
		IntOp $ProgressBar_Counter $ProgressBar_Counter - 1
		SendMessage $ProgressBar ${PBM_SETPOS} $ProgressBar_Counter 0
		${IF} $ProgressBar_Counter S== 0
				StrCpy $ProgressBar_Counter 100
				SendMessage $ProgressBar ${PBM_SETPOS} $ProgressBar_Counter 0
				${NSD_SetImage} $BMP_SlideShow "$EXEDIR\b.bmp" $0
				StrCpy $SlideShow_Type "b.bmp"
				

				
		${EndIF}
${ElseIF} $SlideShow_Type S== "b.bmp"
		IntOp $ProgressBar_Counter $ProgressBar_Counter - 1
		SendMessage $ProgressBar ${PBM_SETPOS} $ProgressBar_Counter 0
		${IF} $ProgressBar_Counter S== 0
				StrCpy $ProgressBar_Counter 100
				SendMessage $ProgressBar ${PBM_SETPOS} $ProgressBar_Counter 0
				${NSD_SetImage} $BMP_SlideShow "$EXEDIR\a.bmp" $0
				StrCpy $SlideShow_Type "a.bmp"
		${EndIF}
${EndIF}
FunctionEnd
i want the Loop Separately do it job AND Also the SlideShow Separately do it job without Stoping

also in this when loop runned after 5 sec if user clicked on gui,Application Not Responding...
Anders#
You can't use a loop either. No long loops or sleeps on the UI thread. Sections run in a different thread and this is where you should perform long operations.