With the object VariableScript it is possible to run a C # script to the occurrence of a certain event.
The events that lead to the execution of the script may be:
Change value of the variable;
Update of the variable;
Upon request by invoking the method “Execute”
The following code shows how to configure components to use iTools objects VariableScript:
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 |
using System; using System.Collections.Generic; using System.Text; namespace IToolSVariableScriptSample { class Program { static void Main(string[] args) { IToolS.Components.ComponentBase.RaiseEventsOnMainThread = false; IToolS.Components.Communication.VariableScript variableStript = new IToolS.Components.Communication.VariableScript(); IToolS.Components.Communication.Group group = new IToolS.Components.Communication.Group(); IToolS.Components.Communication.Client client = new IToolS.Components.Communication.Client(); IToolS.Components.IOServers.IOServer ioServer = new IToolS.Components.IOServers.IOServer(); client.IOServer = ioServer; client.Group = group; group.Add(variableStript); ioServer.Name = "Memory"; variableStript.VariableName = "variableScript"; // the script runs every change value variableStript.ExecuteMode = IToolS.Components.Communication.ExecuteMode.OnChanged; // include references to the assemblies to be used for compiling the script variableStript.References = new String[] { "System.Windows.Forms.dll" }; // insert the script to run at each change value variableStript.Script = "System.Windows.Forms.MessageBox.Show(\"Name: \" + " + "variableScript.VariableName + \"Value: \" + " + "Convert.ToString(variableScript.Value))"; variableStript.Activate(); client.Start(); Console.WriteLine("Press ENTER to exit"); Console.ReadLine(); } } } |