The page where you read about threads is here:
Each script and EA runs its own thread. Only indicators share a common thread with the MT4 GUI. I'm well aware of this, which I why I avoid using while loops in all my indicators, so that the indicator doesn't go into an infinite loop and freeze MT4's GUI.
I use several WinAPI functions in my scripts and indicators. Only PostMessageW has caused a problem so far.
....sigh....I wonder what the problem is with PostMessageW in a script. I haven't tested it in an EA. Does it work without crashing the terminal?I
As I said before: "Consider using your code in an EA and this way the PostMessageW command will not crash your MT4."
My situation is this:
I would like to place an indicator on the chart just as I'm about to place a trade. I don't want the indicator running constantly. I would like to press a hotkey and then have the indicator be instantly placed on the chart without it showing the config dialog box. I would like the script to be linked to the hotkey, to run just once and perform just this very task - placing the indicator on the chart and getting rid of the dialog box without any manual input from me. The reason I go through the trouble of trying to get a script to do all this is to get rid of the config dialog box. I've got multiple charts open and I don't want to be clicking OK to get rid of the dialog box all the time. One hotkey press and the indicator should be up and running. That's what I want.
So you're saying that PostMessageW only crashes the terminal when it's called from a script? Why does it work in an EA and not in a script? What is the deeper programmatic reason for this?
Probably you can prepare a template with this indicator (and required parameters) and then just switch to/from this template when needed. Hence you don't need any scripts, Windows messaging, or other automation.