-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest_1.au3
76 lines (63 loc) · 1.51 KB
/
test_1.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#NoTrayIcon ; Should add this to prevent tray icon in sub-thread.
#include 'N.au3'
; This test spawns a thread on every button click.
; Get global shared object.
global $g = NGlobal()
; task 1
func task_1($l)
; Set last task.
$g.last = 'task_1'
; Get message from shared.
local $msg = $l.message
MsgBox(0, 'Task 1 (ID: ' & NGetId() & ')', $msg)
endfunc
; task 2
func task_2($l)
; Set last task.
$g.last = 'task_2'
; Get some data.
local $msg = StringFormat('Sum %d + %d = %d.', $l.a, $l.b, $l.a + $l.b)
MsgBox(0, 'Task 2 (ID: ' & NGetId() & ')', $msg)
endfunc
; main
func main()
; Create GUI with 3 buttons.
GUICreate('Test 1', 300, 180)
local $btn1 = GUICtrlCreateButton('Task 1', 20, 50, 80, 30)
local $btn2 = GUICtrlCreateButton('Task 2', 120, 50, 80, 30)
local $btn3 = GUICtrlCreateButton('Main', 60, 100, 80, 30)
GUISetState(@SW_SHOW)
local $count = 0
; GUI message loop.
while true
switch GUIGetMsg()
; close
case -3
exit
; button 1
case $btn1
; Create local shared.
local $l = NLocal()
; Set .message prop.
$l.message = StringFormat('Hi, this is a message (%d).', $count)
$count += 1
; Run task_1.
NRun('task_1', $l)
; button 2
case $btn2
; Create local shared.
local $l = NLocal()
; Set some data.
$l.a = 10
$l.b = 5
; Run task_2.
NRun('task_2', $l)
; button 3
case $btn3
; Get .last from global.
MsgBox(0, 'Main', 'Last spawned thread: ' & $g.last)
endswitch
wend
endfunc
; Execute main entry.
NMain('main')