Post by _3D_ » 04 Jan 2018, 06:16
As I see that no ALL task forced closed
https://lexikos.github.io/v2/docs/commands/For.htm
Existing key-value pairs may be modified during the loop, but inserting or removing keys may cause some items to be skipped or enumerated multiple times. One workaround is to build a list of keys to remove, then use a second loop to remove the keys after the first loop completes.
I start investigate why and result:
https://autohotkey.com/boards/viewtopic.php?p=192392#p192392https://autohotkey.com/boards/viewtopic.php?p=192750#p192750
Revised class Task:
Code: [Select all] [Expand]GeSHi © Codebox Plus
;Copyright (c) D.Donchev
class Task {
static List:= [] ;static list
;mode
; 0x01 - terminate task and delete from list (keep/kill child when parent close)
; 0x02 - delete default VAR file
; 0x04 - delete script file
; 0x08 - kill task
;
; 0x10 - runwait
; 0x20 - run when new Task() (run without using this.run())
; 0x40 - end when new Task() (end without using this.end())
;example:
; new Task(".\test.ahk", 0x73) ;just one line
; run test.ahk
; wait to close
; delete from list
; delete var file
;default
; 0x13 - runwait|delete var file|close task
;most used
; 0x73 - run auto|end auto|runwait|delete var file|close task
__new(name, mode:= 0x13) {
this.mode:= mode
this.name:= name
Task.List[this]:= ""
this.ini() ;set default values
if this.mode & 0x20
this.run() ;run task
if this.mode & 0x40
this.end() ;end task
}
set(var, val, opt:="") { ;var val [ini:iniName sec:iniSection]
this.ini(ini, sec, opt)
iniWrite(val, ini, sec, var)
return val
}
get(var, opt:="") { ;var [ini:iniName sec:iniSection]
this.ini(ini, sec, opt)
return iniRead(ini, sec, var)
}
;mode 1 - wait
; 0 - dont wait
; -1 - use this.mode (default)
run(para:="", wait:= -1) { ;execute task
run("autohotkey.exe " this.name " " para,,,pid) ;send parameters correctly
this.PID:= pid ;take PID immediately
if (wait == -1? this.mode & 0x10: wait)
ProcessWaitClose(this.PID) ;runwait
return this
}
static end:= func("__Task_end") ; byRef this external function
__delete() {
if this.mode != "" { ;prevent second run
;0x08 - kill or 0x01 - close
if this.mode & 0x80
ProcessClose(this.pid)
else if this.mode & 0x09 {
DetectHiddenWindows("On")
winClose("ahk_pid " this.PID)
}
if this.mode & 0x02 ;0x02 - delete default task.ahk.VAR !!!
FileDelete(this.name ".VAR")
if this.mode & 0x04 ;0x04 - delete task.ahk
FileDelete(this.name)
this.mode:= this.name:= "" ;prevent second run
} }
; ini(ini, sec) ;current values
; ini(ini, sec, "ini:file.ini|sec:input") ;temporary values
; ini(ini, sec, "set:|ini:ini.ext|sec:1") ;set new values
; | ;delimiter (space is not delimiter)
; set: ;set command
; ini:c:\long path\long name.ini ;ini file name
; sec:some text ;section name
; ini(ini, sec, 0) ;reset values
ini(byRef ini:= "", byRef sec:= "", opt:= "") { ;DRY set:|ini:iniName|sec:iniSection
;if this.file not set OR opt == 0 (0 or "0")
if !this.file || opt == 0 ;set default values
this.file:= "ini:" this.name "|sec:VAR"
;if opt != 0 (0 or "0" or "") use opt else use this.file
opt:= opt? opt: this.file
if RegExMatch(opt, "i)ini:([\w\\:. ]+)(p*)", arg) ;ini:
ini:= arg[1]
if RegExMatch(opt, "i)sec:([\w ]+)(p*)" , arg) ;sec:
sec:= arg[1]
if RegExMatch(opt, "i)set:", arg) ;set:
this.file:= "ini:" ini "|sec:" sec
;dont forget it is your script - using it incorrect doing incorrect
}
}
__Task_end(byRef this) { ;clear reference in list and in calling var
if type(this) != "Class" {
Task.List.Delete(this)
this.__delete() ;forced __delete() if other references
this:= "" ;autocall __delete() if no more references
} } ;class Task ------------------------------------------------------------------
__onExit() {
;Task.List:= [] ;https://autohotkey.com/boards/viewtopic.php?p=192750#p192750
while !isEmpty {
isEmpty:= 1
for key in Task.List {
key.end()
isEmpty:= 0
} } }
OnExit( "__onExit")
__scExit() { ;script exit
ExitApp
}
OnMessage(0x10, "__scExit") ;WM_CLOSE
OnMessage(0x11, "__scExit") ;WM_QUERYENDSESSION
It is completely compatible with early version.
Last edit 11.Jan.2018
As I see that no ALL task forced closed[quote]https://lexikos.github.io/v2/docs/commands/For.htm
Existing key-value pairs may be modified during the loop, but inserting or removing keys may cause some items to be skipped or enumerated multiple times. One workaround is to build a list of keys to remove, then use a second loop to remove the keys after the first loop completes.[/quote]I start investigate why and result:
[url]https://autohotkey.com/boards/viewtopic.php?p=192392#p192392[/url]
[url]https://autohotkey.com/boards/viewtopic.php?p=192750#p192750[/url][color=#FF0000][b]
Revised class Task[/b][/color]:[code];Copyright (c) D.Donchev
class Task {
static List:= [] ;static list
;mode
; 0x01 - terminate task and delete from list (keep/kill child when parent close)
; 0x02 - delete default VAR file
; 0x04 - delete script file
; 0x08 - kill task
;
; 0x10 - runwait
; 0x20 - run when new Task() (run without using this.run())
; 0x40 - end when new Task() (end without using this.end())
;example:
; new Task(".\test.ahk", 0x73) ;just one line
; run test.ahk
; wait to close
; delete from list
; delete var file
;default
; 0x13 - runwait|delete var file|close task
;most used
; 0x73 - run auto|end auto|runwait|delete var file|close task
__new(name, mode:= 0x13) {
this.mode:= mode
this.name:= name
Task.List[this]:= ""
this.ini() ;set default values
if this.mode & 0x20
this.run() ;run task
if this.mode & 0x40
this.end() ;end task
}
set(var, val, opt:="") { ;var val [ini:iniName sec:iniSection]
this.ini(ini, sec, opt)
iniWrite(val, ini, sec, var)
return val
}
get(var, opt:="") { ;var [ini:iniName sec:iniSection]
this.ini(ini, sec, opt)
return iniRead(ini, sec, var)
}
;mode 1 - wait
; 0 - dont wait
; -1 - use this.mode (default)
run(para:="", wait:= -1) { ;execute task
run("autohotkey.exe " this.name " " para,,,pid) ;send parameters correctly
this.PID:= pid ;take PID immediately
if (wait == -1? this.mode & 0x10: wait)
ProcessWaitClose(this.PID) ;runwait
return this
}
static end:= func("__Task_end") ; byRef this external function
__delete() {
if this.mode != "" { ;prevent second run
;0x08 - kill or 0x01 - close
if this.mode & 0x80
ProcessClose(this.pid)
else if this.mode & 0x09 {
DetectHiddenWindows("On")
winClose("ahk_pid " this.PID)
}
if this.mode & 0x02 ;0x02 - delete default task.ahk.VAR !!!
FileDelete(this.name ".VAR")
if this.mode & 0x04 ;0x04 - delete task.ahk
FileDelete(this.name)
this.mode:= this.name:= "" ;prevent second run
} }
; ini(ini, sec) ;current values
; ini(ini, sec, "ini:file.ini|sec:input") ;temporary values
; ini(ini, sec, "set:|ini:ini.ext|sec:1") ;set new values
; | ;delimiter (space is not delimiter)
; set: ;set command
; ini:c:\long path\long name.ini ;ini file name
; sec:some text ;section name
; ini(ini, sec, 0) ;reset values
ini(byRef ini:= "", byRef sec:= "", opt:= "") { ;DRY set:|ini:iniName|sec:iniSection
;if this.file not set OR opt == 0 (0 or "0")
if !this.file || opt == 0 ;set default values
this.file:= "ini:" this.name "|sec:VAR"
;if opt != 0 (0 or "0" or "") use opt else use this.file
opt:= opt? opt: this.file
if RegExMatch(opt, "i)ini:([\w\\:. ]+)(p*)", arg) ;ini:
ini:= arg[1]
if RegExMatch(opt, "i)sec:([\w ]+)(p*)" , arg) ;sec:
sec:= arg[1]
if RegExMatch(opt, "i)set:", arg) ;set:
this.file:= "ini:" ini "|sec:" sec
;dont forget it is your script - using it incorrect doing incorrect
}
}
__Task_end(byRef this) { ;clear reference in list and in calling var
if type(this) != "Class" {
Task.List.Delete(this)
this.__delete() ;forced __delete() if other references
this:= "" ;autocall __delete() if no more references
} } ;class Task ------------------------------------------------------------------
__onExit() {
;Task.List:= [] ;https://autohotkey.com/boards/viewtopic.php?p=192750#p192750
while !isEmpty {
isEmpty:= 1
for key in Task.List {
key.end()
isEmpty:= 0
} } }
OnExit( "__onExit")
__scExit() { ;script exit
ExitApp
}
OnMessage(0x10, "__scExit") ;WM_CLOSE
OnMessage(0x11, "__scExit") ;WM_QUERYENDSESSION[/code]It is completely compatible with early version.
Last edit 11.Jan.2018