-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathControlSystem.cs
More file actions
71 lines (60 loc) · 1.98 KB
/
ControlSystem.cs
File metadata and controls
71 lines (60 loc) · 1.98 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using Crestron.SimplSharp; // For Basic SIMPL# Classes
using Crestron.SimplSharpPro; // For Basic SIMPL#Pro classes
using Crestron.SimplSharpPro.CrestronThread; // For Threading
using Crestron.SimplSharpPro.Diagnostics; // For System Monitor Access
using Crestron.SimplSharpPro.DeviceSupport; // For Generic Device Support
namespace CleanUpExample
{
public class ControlSystem : CrestronControlSystem
{
private Thread _unstoppable;
private bool _running;
public ControlSystem() : base()
{
try
{
Thread.MaxNumberOfUserThreads = 20;
CrestronEnvironment.ProgramStatusEventHandler += ProgramEventHandler;
}
catch (Exception e)
{
ErrorLog.Error("Error in the constructor: {0}", e.Message);
}
}
public override void InitializeSystem()
{
try
{
_unstoppable = new Thread(InfiniteLoop, null);
}
catch (Exception e)
{
ErrorLog.Error("Error in InitializeSystem: {0}", e.Message);
}
}
void ProgramEventHandler(eProgramStatusEventType type)
{
if (type == eProgramStatusEventType.Stopping)
_running = false;
}
object InfiniteLoop(object userObj)
{
var toggle = false;
Thread.Sleep(1000);
CrestronConsole.PrintLine("Starting our loop: ");
_running = true;
while (_running)
{
toggle = !toggle;
Thread.Sleep(1500);
if (toggle)
CrestronConsole.Print("/");
else
CrestronConsole.Print("\\");
}
CrestronConsole.PrintLine("Out of the loop!");
return null;
}
}
}