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
Previous revision
compcode [2011/01/05 16:33]
hourdin update again
— (current)
Line 1: Line 1:
-====== Sample of a Bean ====== 
  
-===== Source Code ===== 
- 
-Here is a sample code of a component in C# (save this to a file called Your_CSharpBean_Name.cs) : 
- 
-<code csharp> 
-using WComp.Beans; ​     // Contains the definition of the [Bean] attribute 
-using System.Threading;​ // For the thread demo purposes 
- 
-namespace Your_Namespace_Name { 
- 
-    [Bean] 
-    public class Your_CSharpBean_Name : IThreadCreator { 
-        private Thread t;      // Private attributes of the class 
-        private volatile bool run; 
-        private volatile int eventValue; 
- 
-        public Your_CSharpBean_Name() { 
-            // Put here your init instructions 
-            t = new Thread(new ThreadStart(ThreadLoopMethod));​ 
-            run = false; 
-            eventValue = 10; 
-        } 
- 
-        public void Start() {  // method starting the thread 
-            if (!run) { 
-                run = true; 
-                t.Start(); ​ 
-            }  
-        } 
-        public void Stop() {   // since version 2.4.0.856, 
-            run = false; ​      // IThreadCreator defines the Stop() method 
-        }  
- 
-         // Loop sample 
-         ​public void ThreadLoopMethod() { 
-             ​while(run) { 
-                 ​Thread.Sleep(1000);​ 
-                 // Check if the output is connected 
-                 ​if(Output_Sample != null) 
-                     // call the connected methods sequentially 
-                     ​Output_Sample(eventValue);​ 
-                // and so on... 
-             } 
-        } 
- 
-        // --- Start: Input port sample --- 
-        // an input port is a public method (like below) 
-        public void Input_Sample(int intParam) { 
-            eventValue = intParam; 
-            // No return value is expected in WComp: 
-            // results are given using events 
-        } 
-        // --- End: Input port sample --- 
- 
-        // --- Start: Output port sample --- 
-        public delegate void Output_Sample_Signature(int val); 
-        // The delegate defines the signature of the output method 
-        public event Output_Sample_Signature Output_Sample;​ 
-        // The output port is the event, named here Output_Sample 
-        // --- End: Output port sample --- 
-    } 
-} 
-</​code>​ 
- 
- 
- 
-===== Compilation ===== 
- 
-Here is a sample of the command line compilation:​ 
-<​code>​ 
-csc.exe /​target:​library /​r:​Beans.dll Sample_Component.cs 
-</​code>​ 
- 
-You will find Beans.dll in the SharpWComp distrib. 
  • compcode.1294241595.txt.gz
  • Last modified: 2011/01/05 16:33
  • by hourdin