Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
compcode [2007/06/13 05:38] – lavirotte | compcode [2011/01/05 15:26] – fixes in the code, update to new version hourdin | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Sample | + | ====== Sample |
===== Source Code ===== | ===== Source Code ===== | ||
- | Here is the sample code of a component in c# (save this to a le called | + | Here is a sample code of a component in C# (save this to a file called |
<code csharp> | <code csharp> | ||
- | using WComp.Beans; | + | using WComp.Beans; |
using System.Threading; | using System.Threading; | ||
Line 12: | Line 12: | ||
[Bean] | [Bean] | ||
- | public class Your_CSharpBean_Name { | + | public class Your_CSharpBean_Name |
+ | 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(); | + | |
} | } | ||
+ | |||
+ | public void Start() { | ||
+ | if (!run) { | ||
+ | run = true; | ||
+ | t.Start(); | ||
+ | } | ||
+ | } | ||
+ | public void Stop() { // since version 2.4.0.856, | ||
+ | run = false; | ||
+ | } | ||
// Loop sample | // Loop sample | ||
| | ||
- | | + | |
| | ||
| | ||
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 | + | public |
string pn = param_name; // You may use the parameters | string pn = param_name; // You may use the parameters | ||
- | | + | // No return |
+ | // 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 |
public event Output_Sample_Signature Output_Sample; | public event Output_Sample_Signature Output_Sample; | ||
- | // The output port is the event (before) | + | // The output port is the event, named here Output_Sample |
// --- End: Output port sample --- | // --- End: Output port sample --- | ||
} | } | ||
} | } | ||
</ | </ | ||
+ | |||
+ | |||
===== Compilation ===== | ===== Compilation ===== | ||
- | Wcomp distrib. | + | Here is a sample of the command line compilation: |
- | < | + | < |
- | csc.exe / | + | csc.exe / |
</ | </ | ||
+ | |||
+ | You will find Beans.dll in the SharpWComp distrib. |