Skip to content

Commit fcb084c

Browse files
committed
Add helper method to dispose StreamInfo[] arrays
1 parent a1c210a commit fcb084c

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

LSL.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,17 @@ protected override bool ReleaseHandle()
4646
return true;
4747
}
4848
}
49-
public class liblsl
49+
public static class liblsl
5050
{
51+
/// <summary>
52+
/// Helper method to dispose a StreamInfo[] array
53+
/// </summary>
54+
/// <param name="arr">Array to be disposed</param>
55+
public static void DisposeArray(this StreamInfo[] array)
56+
{
57+
foreach (var si in array) si.Dispose();
58+
}
59+
5160
/// <summary>Constant to indicate that a stream has variable sampling rate.</summary>
5261
public const double IRREGULAR_RATE = 0.0;
5362

examples/HandleMetaData/HandleMetaData.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Threading;
32
using LSL;
43

54
namespace ConsoleApplication1
@@ -8,11 +7,15 @@ class Program
87
{
98
static void Main(string[] args)
109
{
10+
{
11+
using liblsl.StreamInfo inf_ = new liblsl.StreamInfo("Test", "EEG", 8, 100, liblsl.channel_format_t.cf_double64, "test1234");
12+
Console.Out.WriteLine("Test");
13+
}
1114
// create a new StreamInfo and declare some meta-data (in accordance with XDF format)
12-
liblsl.StreamInfo info = new liblsl.StreamInfo("MetaTester", "EEG", 8, 100, liblsl.channel_format_t.cf_float32, "myuid323457");
15+
using liblsl.StreamInfo info = new liblsl.StreamInfo("MetaTester","EEG",8,100,liblsl.channel_format_t.cf_float32,"myuid323457");
1316
liblsl.XMLElement chns = info.desc().append_child("channels");
14-
String[] labels = { "C3", "C4", "Cz", "FPz", "POz", "CPz", "O1", "O2" };
15-
for (int k = 0; k < labels.Length; k++)
17+
String[] labels = {"C3","C4","Cz","FPz","POz","CPz","O1","O2"};
18+
for (int k=0;k<labels.Length;k++)
1619
chns.append_child("channel")
1720
.append_child_value("label", labels[k])
1821
.append_child_value("unit", "microvolts")
@@ -29,10 +32,12 @@ static void Main(string[] args)
2932
// === the following could run on another computer ===
3033

3134
// resolve the stream and open an inlet
32-
liblsl.StreamInfo[] results = liblsl.resolve_stream("name", "MetaTester");
33-
liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0]);
35+
liblsl.StreamInfo[] results = liblsl.resolve_stream("name","MetaTester");
36+
using liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0]);
37+
foreach (liblsl.StreamInfo si in results) si.Dispose();
38+
3439
// get the full stream info (including custom meta-data) and dissect it
35-
liblsl.StreamInfo inf = inlet.info();
40+
using liblsl.StreamInfo inf = inlet.info();
3641
Console.WriteLine("The stream's XML meta-data is: ");
3742
Console.WriteLine(inf.as_xml());
3843
Console.WriteLine("The manufacturer is: " + inf.desc().child_value("manufacturer"));

0 commit comments

Comments
 (0)