From WikiChip
Difference between revisions of "mirc/thread"
< mirc

(mIRC's message loop)
(Nested call to the message loop)
Line 16: Line 16:
 
== Nested call to the message loop ==
 
== Nested call to the message loop ==
  
The trick is to "call" the message loop yourself, handling one more message before returning to handling the current message
+
The trick is to "call" the message loop yourself (you or mIRC, typically), handling one more message while the current one is running (nested execution) before returning to handling this current message
  
 
=== $input ===
 
=== $input ===
Line 24: Line 24:
 
<source>
 
<source>
 
alias test {
 
alias test {
echo -a 1
+
set %test 1
 
noop $input(text,e)
 
noop $input(text,e)
echo -a 2
+
echo -a %test
 
}
 
}
 
</source>
 
</source>
  
When you call /test, the scripting engine has to wait for your input before processing the rest of the code, just waiting for your input would freeze mirc since no others messages are processed while one message is processed, in normal time, so mIRC itself call the message loop and process some of the messages,
+
When you call /test, the scripting engine has to wait for your input before processing the rest of the code, represented by an infinite while loop.
 +
 
 +
Just waiting for your input would freeze mirc since no others messages would be processed (how things usually works), so mIRC itself call the message loop once per iteration of that infinite while loop, and process more messages.
 +
 
 +
This can be demonstrated by running /test above, from a desktop window, (possibly with the 'u' switch of $input?) and then going back to mIRC and executing /set %test 2, when $input returns, 2 will be displayed, showing that $input allowed you to click back to mirc and running the scripting engine with /set, all of which are the result of handling the message loop
 +
 
 +
=== Whilefix Dll ===
 +
 
 +
Since a very long time, a dll called whilefix.dll exists which will 'fix' your while loop in mIRC (pretty catchy isn't it?).
 +
 
 +
What this dll does is exactly what $input does, it calls the message loop and allow more message to be processed:
 +
 
 +
<source>
 +
while (condition) {
 +
;call the WhileFix routine
 +
dll path\to\whilefix.dll WhileFix
 +
}
 +
</source>

Revision as of 10:00, 9 June 2018

This page aims to discuss threads in mIRC, delayed execution and non blocking while loop.

Thread

There are no thread in mIRC, mIRC is single threaded, always.

Sometimes it looks like mIRC can do multiple things at the same time without freezing, this is never the case, below we will discuss the different illusions that can occur.

mIRC's message loop

mIRC, just like many Windows applications, is based on a loop which processes messages, messages correspond to some kind of event, new data on a socket, a click on a button etc. For each iteration of the loop, one message only is processed and then the loop repeats.

This approach is what allows mIRC, or scripters to create the thread illusions.

Nested call to the message loop

The trick is to "call" the message loop yourself (you or mIRC, typically), handling one more message while the current one is running (nested execution) before returning to handling this current message

$input

mIRC itself, with $input, does this:

alias test {
set %test 1
noop $input(text,e)
echo -a %test
}

When you call /test, the scripting engine has to wait for your input before processing the rest of the code, represented by an infinite while loop.

Just waiting for your input would freeze mirc since no others messages would be processed (how things usually works), so mIRC itself call the message loop once per iteration of that infinite while loop, and process more messages.

This can be demonstrated by running /test above, from a desktop window, (possibly with the 'u' switch of $input?) and then going back to mIRC and executing /set %test 2, when $input returns, 2 will be displayed, showing that $input allowed you to click back to mirc and running the scripting engine with /set, all of which are the result of handling the message loop

Whilefix Dll

Since a very long time, a dll called whilefix.dll exists which will 'fix' your while loop in mIRC (pretty catchy isn't it?).

What this dll does is exactly what $input does, it calls the message loop and allow more message to be processed:

while (condition) {
;call the WhileFix routine
dll path\to\whilefix.dll WhileFix
}