-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommandProcessor.cs
85 lines (75 loc) · 2.99 KB
/
CommandProcessor.cs
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/******************************************************************************
* *
* PROJECT : Eos Digital camera Software Development Kit EDSDK *
* *
* Description: This is the Sample code to show the usage of EDSDK. *
* *
* *
*******************************************************************************
* *
* Written and developed by Canon Inc. *
* Copyright Canon Inc. 2018 All Rights Reserved *
* *
*******************************************************************************/
using System;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using System.Threading;
namespace CameraControl
{
class CommandProcessor
{
private ConcurrentQueue<Command> _commandQueue = new ConcurrentQueue<Command>();
private bool _running = false;
private Task _task = null;
public void Start()
{
_running = true;
_task = Task.Run(() =>
{
while (_running)
{
Thread.Sleep(1);
Command command = null;
_commandQueue.TryDequeue(out command);
if (command != null)
{
if (command.Execute() == false)
{
//If commands that were issued fail ( because of DeviceBusy or other reasons )
// and retry is required , note that some cameras may become unstable if multiple
// commands are issued in succession without an intervening interval.
//Thus, leave an interval of about 500 ms before commands are reissued.
Thread.Sleep(500);
_commandQueue.Enqueue(command);
}
}
}
});
// Command of end
//if (_closeCommand != NULL)
//{
// _closeCommand->execute();
// delete _closeCommand;
// _closeCommand = NULL;
//}
}
public void Stop()
{
_running = false;
try
{
_task.Wait();
}
catch (AggregateException)
{
// ...
}
_task.Dispose();
}
public void PostCommand(Command command)
{
_commandQueue.Enqueue(command);
}
}
}