Advertisement
HoangVuIT

How to use Global variable with true-autoit-multi-threading

Mar 22nd, 2023
1,912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 0.77 KB | Source Code | 0 0
  1. #NoTrayIcon ; Should add this to prevent tray icon in sub-thread.
  2. #include 'N.au3'
  3.  
  4. global $g = NGlobal()
  5.  
  6.  
  7. func task_1($l)
  8.     $g.number = 50
  9. endfunc
  10.  
  11. func task_2($l)
  12.  
  13.     local $msg = StringFormat('Number is %d', $g.number)
  14.     MsgBox(0, 'Task 2 (ID: ' & NGetId() & ')', $msg)
  15. endfunc
  16.  
  17. ; main
  18. func main()
  19.     ; Create GUI with 3 buttons.
  20.     GUICreate('Test 1', 300, 180)
  21.     local $btn1 = GUICtrlCreateButton('Task 1', 20, 50, 80, 30)
  22.     local $btn2 = GUICtrlCreateButton('Task 2', 120, 50, 80, 30)
  23.     GUISetState(@SW_SHOW)
  24.  
  25.     $g.number = 20
  26.  
  27.     while true
  28.         switch GUIGetMsg()
  29.             ; close
  30.             case -3
  31.                 exit
  32.  
  33.             ; button 1
  34.             case $btn1
  35.  
  36.                 NRun('task_1')
  37.  
  38.             ; button 2
  39.             case $btn2
  40.                 NRun('task_2')
  41.         endswitch
  42.     wend
  43. endfunc
  44.  
  45. ; Execute main entry.
  46. NMain('main')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement