Archive: UI dead when button click event execute long time function


UI dead when button click event execute long time function
Hi, My problem is very easy to be reproduced.

I have a background running function which will be launched when a button was clicked. But it will cause all UI be locked and looks urgly. Please help me out of the problem.

The code could be like below. It's example code under NSIS example folder. I just inserted "Sleep 10000" in button function. And it will lock the UI.

!include nsDialogs.nsh
!include LogicLib.nsh

Name "nsDialogs Example"
OutFile "nsDialogs Example.exe"

XPStyle on

Page license
Page custom nsDialogsPage

Var BUTTON
Var EDIT
Var CHECKBOX

Function nsDialogsPage

nsDialogs::Create /NOUNLOAD 1018
Pop $0

GetFunctionAddress $0 OnBack
nsDialogs::OnBack /NOUNLOAD $0

${NSD_CreateButton} 0 0 100% 12u Test
Pop $BUTTON
GetFunctionAddress $0 OnClick
nsDialogs::OnClick /NOUNLOAD $BUTTON $0

${NSD_CreateText} 0 35 100% 12u hello
Pop $EDIT
GetFunctionAddress $0 OnChange
nsDialogs::OnChange /NOUNLOAD $EDIT $0

${NSD_CreateCheckbox} 0 -50 100% 8u Test
Pop $CHECKBOX
GetFunctionAddress $0 OnCheckbox
nsDialogs::OnClick /NOUNLOAD $CHECKBOX $0

${NSD_CreateLabel} 0 40u 75% 40u "* Type `hello there` above.$\n* Click the button.$\n* Check the checkbox.$\n* Hit the Back button."
Pop $0

nsDialogs::Show

FunctionEnd

Function OnClick

Pop $0 # HWND
Sleep 10000
MessageBox MB_OK clicky

FunctionEnd

Function OnChange

Pop $0 # HWND

System::Call user32::GetWindowText(i$EDIT,t.r0,i${NSIS_MAX_STRLEN})

${If} $0 == "hello there"
MessageBox MB_OK "right back at ya"
${EndIf}

FunctionEnd

Function OnBack

MessageBox MB_YESNO "are you sure?" IDYES +2
Abort

FunctionEnd

Function OnCheckbox

Pop $0 # HWND

MessageBox MB_OK "checkbox clicked"

FunctionEnd

Section
SectionEnd


Right before you sleep (or whatever the button is really going to do) you could disable the other controls/buttons to indicate that they are not currently listening to the user. Then when the sleep/task completes, you reenable the controls again.

EnableWindow $Edit 0
GetDlgItem $0 $HWNDPARENT 1 'next button
EnableWindow $0 0
EnableWindow $CHECKBOX 0

Sleep 10000

EnableWindow $Edit 1
GetDlgItem $0 $HWNDPARENT 1 'next button
EnableWindow $0 1
EnableWindow $CHECKBOX 1

Don

Sorry, it doesn't help. You can see the window isn't refresh when you click the button. Well, other controls are disabled but it doesn't mean the UI can response any mouse command like move window or minimize the window. I hope the UI is still alive after user click button.


i think thats a issue with nsdialogs ,kichik has said
"nsDialogs doesn't support asynchronous operations so you can't keep on doing something, updating the GUI while you do it and still have user interaction."
ive kinda ran into that my self with a extracting a big file