-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPC-Example-LargeData.au3
More file actions
65 lines (55 loc) · 2.7 KB
/
IPC-Example-LargeData.au3
File metadata and controls
65 lines (55 loc) · 2.7 KB
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
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.18.0
Author: Kanashius
Script Function:
Example script for the IPC InterProcessCommunication UDF.
This example shows how to handle large amount of data.
#ce ----------------------------------------------------------------------------
#include "IPC.au3"
Global Const $iCOMMAND_TEST = 1, $iCOMMAND_UNKNOWN = 2, $iCOMMAND_PROGRESS = 3
; limit the amount of tcprecv calls to 10, so the main process does not freeze
__IPC_StartUp($__IPC_LOG_TRACE, 0, 10)
; check if the call is a sub process and start the respective function
__IPC_SubCheck("_SubProcess", "_MainProcess", Default, Default, $__IPC_LOG_TRACE)
If @error Then __IPC_Log($__IPC_LOG_ERROR, "__IPC_SubCheck: "&@error&":"&@extended)
; main/sub process both should call shutdown before exit
__IPC_Shutdown()
Exit
; the main process main method, registered in __IPC_SubCheck to be called when the script is running as main process (no sub process command line arguments detected)
Func _MainProcess()
; start a sub process calling the same script.
; the _CallbackMain method is called for messages received from the sub process
; 100 is the parameter provided to the sub process (total items)
Local $hSubProcess = __IPC_StartProcess("_CallbackMain")
; wait for the sub process to finish
While ProcessExists(__IPC_SubGetPID($hSubProcess)) And Sleep(10)
; handle data coming from sub processes
__IPC_MainProcessing()
ConsoleWrite("Possibly handle gui events"&@crlf)
; Local $iMsg = GUIGetMsg()
; ...
WEnd
EndFunc
; registered as callback in __IPC_StartProcess to be called when data from the sub process is received
Func _CallbackMain($hSubProcess, $iCmd, $arData)
; $hSubProcess can be used to differentiate between different sub processes (if multiple are started with the same callback method)
; $iCmd contains the command send by the server, or Default if only data was sent
; $arData contains an array with all the send data or Default if only a command was sent
ConsoleWrite("----------------------------------------------------"&@crlf)
ConsoleWrite($arData[0]&@crlf)
ConsoleWrite("----------------------------------------------------"&@crlf)
EndFunc
; the sub process main method, registered in __IPC_SubCheck to be called when the script is running as a sub process
Func _SubProcess($hSubProcess)
ConsoleWrite("----------------------------------------------------"&@crlf)
Local $sData = ""
For $i=0 To $__IPC_MaxByteRecv*200 Step 10
If $i<>0 Then $sData &= @CRLF
For $j=0 To 10 Step 1
$sData &= $j
Next
Next
__IPC_SubSend($sData)
; ConsoleWrite($sData&@crlf)
ConsoleWrite("----------------------------------------------------"&@crlf)
EndFunc