The peekMessage()
function is used to get a message from a thread.
The peekMessage()
function returns the message received by the thread associated with the current thread object.
string, number, bool, object, array, null value and other types supported by the system
peekMessage() peekMessage(timeout)
The parameter timeout
is the timeout setting. It will block and wait for the number of milliseconds set by the parameter and return data. If there is no data and the timeout exceeds the limit, a null value will be returned. If timeout
is set to 0 or the timeout
parameter is not passed, it means that the process will block and wait until data is received from the channel. If timeout
is set to -1, it means that the process will not block and return data immediately. If there is no data, a null value will be returned.
timeout false number
function main() {
var t1 = threading.Thread(function() {
for (var i = 0; i < 10; i++) {
Log("thread1 postMessage():", i)
threading.mainThread().postMessage(i)
Sleep(500)
}
})
while (true) {
var msg = threading.currentThread().peekMessage()
Log("main peekMessage():", msg)
if (msg == 9) {
break
}
Sleep(1000)
}
t1.join()
}
Send messages to the main thread from a concurrent thread.
When writing programs, we need to pay attention to thread deadlock problems.
{@fun/Threads/Thread/postMessage postMessage}, {@fun/Threads/Thread/join join}, {@fun/Threads/Thread/terminate terminate}, {@fun/Threads/Thread/getData getData}, {@fun/Threads/Thread/setData setData}, {@fun/Threads/Thread/id id}, {@fun/Threads/Thread/name name}, {@fun/Threads/Thread/eventLoop eventLoop}
threading postMessage