Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
stop/pause/continue subfunction
#2
your stop wasnt working because you were running a new sub func and ending that thread. Need to get handle when you start sub func.

here is working start stop pause resume

Function ListDialogRotate2a
Code:
Copy      Help
str lb_items=
;item 1
;item 2
;item 3
;item 4
;item 5
;item 6
;item 7

str dd=
F
;BEGIN DIALOG
;0 "" 0x90CC0AC8 0x0 0 0 298 136 "{appname}" "4"
;3 ListBox 0x54230901 0x200 0 0 296 114 ""
;21 Button 0x54032000 0x0 5 120 78 14 "START REMOVE" "From top, start removing items one by one[][SHIFT] + left click = starts from BOTTOM"
;23 Button 0x54032000 0x4 95 120 32 14 "REFILL"
;4 Button 0x54032000 0x0 135 120 48 14 "stop"
;5 Button 0x5C012000 0x0 195 120 72 14 "pause/continue"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C00 "*" "" "" ""

str controls = "3"
str lb3
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc v
function# hDlg message wParam lParam
double demo_wait_time=1.0
sel message
,case WM_INITDIALOG
,,int- hThread
,,sub.fill_lb(id(3 hDlg) lb_items)
,case WM_DESTROY
,RemoveProp(id(3 hDlg) "PauseResume") 
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 21 ;; START REMOVING ITEMS FROM LISTBOX
,if(!GetProp(id(3 hDlg) "PauseResume"))
,,,hThread=    mac("sub.remove_item_and_process" "" id(3 hDlg) demo_wait_time hDlg)
,,,TO_Enable(hDlg "5" 1)
,case 23 ;; REFILL THE LISTBOX
,,sub.fill_lb(id(3 hDlg) lb_items)
,case 4 ;; STOP
,,EndThread("" hThread)
,,outt "Stopped?"
,,hThread=!hThread
,,SetProp(id(3 hDlg) "PauseResume" 0)
,,TO_Enable(hDlg "5" 0)
,case 5 ;; PAUSE/CONTINUE: ???
,if(!GetProp(id(3 hDlg) "PauseResume"))
,,SetProp(id(3 hDlg) "PauseResume" 1)
,,outt F"paused..."
,else
,,SetProp(id(3 hDlg) "PauseResume" 0)
,,outt F"continued..."
ret 1

#sub remove_item_and_process
function cid  double'demo_wait_time hdlg
int amount i
amount=LB_GetCount(cid)
if(amount=0)
,mes(F"No content to process" F"test" "!")
,ret
rep amount
,if(GetProp(cid "PauseResume"))
,,rep
,,,if(!GetProp(cid "PauseResume"))
,,,,break
,,,0.1
,LB_GetItemText(cid 0 _s)
,LB_SelectItem(cid 0 1)
,outt F"PROCESSING, {_s}, {i} -> ({i} index listbox content)"
,wait demo_wait_time
,SendMessage(cid LB_DELETESTRING 0 0)
,outt F"PROCESSED, REMOVED: {_s}, {i} -> ({i} index listbox content)"
,out "-"
,i=i+1
SetProp(cid "PauseResume" 0)
TO_Enable(hdlg "5" 0)
mes(F"Finished[]No more content to process" F"test" "i")

#sub fill_lb
function cid str'lb_items

SendMessage(cid LB_RESETCONTENT 0 0) ;; clear first then refill

int cnt
foreach _s lb_items
,LB_Add cid _s cnt
,cnt=cnt+1


Messages In This Thread
stop/pause/continue subfunction - by r0n - 07-30-2021, 07:31 PM
RE: stop/pause/continue subfunction - by Kevin - 07-31-2021, 12:46 AM
RE: stop/pause/continue subfunction - by r0n - 07-31-2021, 10:22 AM
RE: stop/pause/continue subfunction - by Kevin - 07-31-2021, 10:37 AM
RE: stop/pause/continue subfunction - by r0n - 07-31-2021, 11:19 AM
RE: stop/pause/continue subfunction - by Kevin - 07-31-2021, 11:39 AM
RE: stop/pause/continue subfunction - by r0n - 08-02-2021, 09:11 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)