Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Performing time-consuming commands or sub-functions from button in dialog
#1
In the code example below, the wmic command or sub-function is executed from a button in a dialog box, and they are quite time-consuming, resulting in the dialog box becoming unresponsive.

How can these commands or functions be executed asynchronously? Or are there any methods to prevent the dialog box from becoming unresponsive?

Thanks in advance for any suggestions and help.
David

Macro Macro25
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Button 0x54032000 0x0 16 16 48 14 "Run wmic"
;4 Button 0x54032000 0x0 112 16 64 14 "Run subFunction"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 3 ;;Run wmic
,str cl=
,;wmic PRODUCT where "name='APP name'" call Uninstall
,RunConsole2 cl
,
,case 4 ;;Run subFunction
,sub.subTest
ret 1

#sub subTest
rep 20
,0.5
#2
run the code from subfunction in a separate thread using mac

Function Function54
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Button 0x54032000 0x0 16 16 48 14 "Run wmic"
;4 Button 0x54032000 0x0 112 16 64 14 "Run subFunction"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 3 ;;Run wmic
,mac "sub.subTest1"
,case 4 ;;Run subFunction
,mac "sub.subTest2"
ret 1

#sub subTest1
str cl=
;wmic PRODUCT where "name='APP name'" call Uninstall
RunConsole2 cl

#sub subTest2
rep 20
,0.5
#3
Kevin, Thanks for your help.

I had a misconception before, thinking that Mac commands cannot be used in an EXE. The code above works well and runs perfectly in the generated EXE.

There are two improvements to be made in the following code:
1. I have added "OnScreenDisplay 'Running . . .'" at the beginning of each sub-function's code. If there are many sub-functions, this is repetitive. Is there a way to simplify them?
2. I would like to lock the operation of all controls in the dialog box while executing the sub-function code, and unlock them again after execution. Is there a simple way to achieve this functionality?

Macro Macro25
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Button 0x54032000 0x0 16 16 48 14 "Run wmic"
;4 Button 0x54032000 0x0 112 16 64 14 "Run subFunction"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 3 ;;Run wmic
,mac "sub.subTest1"
,case 4 ;;Run subFunction
,mac "sub.subTest2"
ret 1

#sub subTest1
OnScreenDisplay "Running . . ."
str cl=
;wmic PRODUCT where "name='App name'" call Uninstall
RunConsole2 cl

#sub subTest2
OnScreenDisplay "Running . . ."
rep 20
,0.5
#4
something like this 

Function Function54
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Button 0x54032000 0x0 16 16 48 14 "Run wmic"
;4 Button 0x54032000 0x0 112 16 64 14 "Run subFunction"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 3 ;;Run wmic
,mac "sub.subMain" "" hDlg 1 "wmic"
,case 4 ;;Run subFunction
,mac "sub.subMain" "" hDlg 2 "subFunction"
ret 1

#sub subMain
function hwnd action ~actionText

TO_Enable hwnd "1-4" 0
actionText -"Running . . ."
OnScreenDisplay actionText -1 0 0 "" 0 0 8
sel action 
,case 1;;Run wmic
,sub.Sub1
,case 2;;Run subFunction
,sub.Sub2
TO_Enable hwnd "1-4" 1

#sub Sub1
str cl=
;wmic PRODUCT where "name='APP name'" call Uninstall
RunConsole2 cl
#sub Sub2
rep 20
,0.5
#5
Thank you, this is exactly what I wanted.


Forum Jump:


Users browsing this thread: 2 Guest(s)