|
|
#1 |
|
Member
Join Date: Jul 2015
Posts: 62
|
NSIS Not responding
Hi All,
During installation , my custom dialog goes into not responding state(ion top of the installer window). The custom dialog has a button which the user can click to stop and uninstall an existing windows service. It works fine most of the times but sometimes when the windows service takes a while to stop, the NSIS window goes into not responding state and I have to cancel the install from the task manager. Here is my code for the custom page buttonClick. In brief, the code below does the following. --Enables the button when dialog is shown --Gets the windows service binary path, based on this the installer knows where the .bat file is to stop and uninstall the service. --Stops the service(this is the piece that's causing the issue) --Uninstall the service --enable the button and also the next button in the dialog EnableWindow $hCtl_ExistingHub_Button1 0 ${NSD_SetText} $hCtl_ExistingHub_Button1 "Stopping Service..." SimpleSC::GetServiceBinaryPath "MyService" Pop $0 Pop $1 Push "$1" ; contains the service executable string Call GetFirstStrPart Pop "$R0" Push "$R0" ;get parent directory from service string Call GetParent Pop $R0 Push "$R0" Call GetParent Pop $R0 SimpleSC::GetServiceStatus "MyService" Pop $0 Pop $1 ${If} $1 == "4" ExecDos::exec /TIMEOUT=5000 /TOSTACK "$R0\bin\stopservice.bat" ;ExecDos::exec /TIMEOUT=5000 "$R0\bin\stopservice.bat" ; Pop $0 MessageBox MB_OK "Existing Service stopped" ${EndIf} ${NSD_SetText} $hCtl_ExistingHub_Button1 "Uninstalling Service..." ExecDos::exec /TIMEOUT=5000 /TOSTACK "$R0\bin\uninstall.bat" MessageBox MB_OK "Existing service uninstalled" ${NSD_SetText} $hCtl_ExistingHub_Button1 "Uninstall" EnableWindow $hCtl_ExistingHub_Button1 1 GetDlgItem $1 $HWNDPARENT 1 ;//Enable "Next" button EnableWindow $1 1 I also tried stopping the service using the SimpleService plugin, this brings up the "Not responding" state too but I don't have to cancel from the task manager as it finally comes back to normal state after sometime. |
|
|
|
|
|
#2 |
|
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
|
You should not really perform operations that take a long time on your custom pages but if you have to, you should take a look at the BgWorker plugin...
IntOp $PostCount $PostCount + 1 |
|
|
|
|
|
#3 |
|
Member
Join Date: Jul 2015
Posts: 62
|
Thank you Anders. It took me a while to understand the BgWorker plugin but it worked out wonderful for me.
http://nsis.sourceforge.net/BgWorker_plug-in For folks who want to know the solution for my issue, this is what I did: --Added the BgWorker plugin in my plugin director --Modified my code this way: EnableWindow $hCtl_ExistingHub_Button1 0 ${NSD_SetText} $hCtl_ExistingHub_Button1 "Stopping Service..." !if 1 GetFunctionAddress $0 workerfunc BgWorker::CallAndWait !else call workerfunc !endif EnableWindow $hCtl_ExistingHub_Button1 1 GetDlgItem $1 $HWNDPARENT 1 ;//Enable "Next" button EnableWindow $1 1 Function workerfunc SimpleSC::GetServiceBinaryPath "MyService" Pop $0 Pop $1 Push "$1" ; contains the service executable string Call GetFirstStrPart Pop "$R0" Push "$R0" ;get parent directory from service string Call GetParent Pop $R0 Push "$R0" Call GetParent Pop $R0 SimpleSC::GetServiceStatus "MyService" Pop $0 Pop $1 ${If} $1 == "4" ExecDos::exec /TIMEOUT=5000 /TOSTACK "$R0\bin\stopservice.bat" ;ExecDos::exec /TIMEOUT=5000 "$R0\bin\stopservice.bat" ; Pop $0 MessageBox MB_OK "Existing Service stopped" ${EndIf} ${NSD_SetText} $hCtl_ExistingHub_Button1 "Uninstalling Service..." ExecDos::exec /TIMEOUT=5000 /TOSTACK "$R0\bin\uninstall.bat" MessageBox MB_OK "Existing service uninstalled" ${NSD_SetText} $hCtl_ExistingHub_Button1 "Uninstall" FunctionEnd |
|
|
|
|
|
#4 |
|
Member
Join Date: Jul 2015
Posts: 62
|
Hi Anders,
I hope I have implemented the BgWorker in the right way. I am also curious to know how does this plugin work? |
|
|
|
|
|
#5 |
|
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
|
Did you read the description section on the wiki page?
IntOp $PostCount $PostCount + 1 |
|
|
|
|
|
#6 |
|
Member
Join Date: Jul 2015
Posts: 62
|
Yes, I did.
This plugin calls the address stored in $0 in a low priority background thread, the "main" thread will process window messages while waiting for the worker thread. Note that some internal functions and 3rd party components might not work in a separate thread! So anything in the function "workerfunc" will be in a lower priority thread? The example which was in the zip file was a little hard to follow. |
|
|
|
|
|
#7 |
|
Major Dude
Join Date: May 2005
Location: New Zealand
Posts: 916
|
All threads have a priority, the default is medium. Low priority means it gets less percentage of the cpu for processing. High priority means that it gets more percentage of the cpu for processing. I've tried changing a process to high priority just to see what it did, and I noticed a slowdown in most other processes ie opening folder explorer or launching another program. It's like using a computer that's transcoding a video at the same time, sluggish. It's pretty good on Windows 10 though.
About things not working in another thread, this is because some programs are not written to take advantage of multiple threads, and two threads trying to access the same item can cause errors or a crash. To fix this there has to be some sort of mutex system (item locking). This is going into programming basics, one example is games. They all use mutexes. "Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me) NSIS 3 POSIX Ninja Wiki Profile |
|
|
|
|
|
#8 |
|
Member
Join Date: Jul 2015
Posts: 62
|
Thank you Jason for the detailed explanation.
I have been really having great fun writing installers in NSIS . A big thanks to folks like you and Anders for making life simple for us. |
|
|
|
![]() |
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|