compcode

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
compcode [2011/01/05 15:43]
hourdin minor spelling fixes
compcode [2011/01/05 16:26]
hourdin fixes in the code, update to new version
Line 12: Line 12:
  
     [Bean]     [Bean]
-    public class Your_CSharpBean_Name {+    public class Your_CSharpBean_Name ​: IThreadCreator ​{ 
 +        private Thread t;      // Private attributes of the class 
 +        private volatile bool run = false;
  
         public Your_CSharpBean_Name() {         public Your_CSharpBean_Name() {
Line 18: Line 20:
             // Example of a loop that call the output             // Example of a loop that call the output
             // every second.             // every second.
-            new Thread(new ThreadStart(ThreadLoopMethod)).Start();+            ​t = new Thread(new ThreadStart(ThreadLoopMethod));​
         }         }
 +
 +        public void Start() {
 +            if (!run) {
 +                run = true;
 +                t.Start(); ​
 +            } 
 +        }
 +        public void Stop() {   // since version 2.4.0.856,
 +            run = false; ​      // IThreadCreator defines the Stop() method
 +        } 
  
          // Loop sample          // Loop sample
          ​public void ThreadLoopMethod() {          ​public void ThreadLoopMethod() {
-             ​while(Thread.CurrentThread.IsAlive) {+             ​while(run) {
                  ​Thread.Sleep(1000);​                  ​Thread.Sleep(1000);​
                  ​double result;                  ​double result;
Line 36: Line 48:
         // --- Start: Input port sample ---         // --- Start: Input port sample ---
         // an input port is a method (below)         // an input port is a method (below)
-        public ​int Input_Sample(string param_name) {+        public ​void Input_Sample(string param_name) {
             string pn = param_name; // You may use the parameters             string pn = param_name; // You may use the parameters
-            ​return 0; // You may return ​anything+            // No return ​value is expected in WComp: 
 +            // results are given using events
         }         }
         // --- End: Input port sample ---         // --- End: Input port sample ---
Line 44: Line 57:
         // --- Start: Output port sample ---         // --- Start: Output port sample ---
         public delegate double Output_Sample_Signature(int param_name);​         public delegate double Output_Sample_Signature(int param_name);​
-        // This is the signature of the output method+        // The delegate defines ​the signature of the output method
         public event Output_Sample_Signature Output_Sample;​         public event Output_Sample_Signature Output_Sample;​
         // The output port is the event, named here Output_Sample         // The output port is the event, named here Output_Sample
  • compcode.txt
  • Last modified: 2011/06/06 10:48
  • by Stéphane Lavirotte