Repository navigation
Expand file tree
/
Copy pathQueue.cs
More file actions
93 lines (82 loc) · 2.54 KB
/
Copy pathQueue.cs
File metadata and controls
93 lines (82 loc) · 2.54 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace QuantBox.XAPI.Callback
{
public class Queue :IDisposable
{
private Proxy proxy;
public IntPtr Handle = IntPtr.Zero;
protected object locker = new object();
public Queue(string path)
{
proxy = new Proxy(path);
Handle = proxy.XRequest((byte)RequestType.Create, IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, 0, IntPtr.Zero, 0, IntPtr.Zero, 0);
}
~Queue()
{
Dispose(false);
}
private bool disposed;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
// Free other state (managed objects).
}
// Free your own state (unmanaged objects).
// Set large fields to null.
Disconnect();
disposed = true;
}
//base.Dispose(disposing);
}
public void Connect()
{
lock (locker)
{
if (proxy != null)
{
// 启动消息队列循环
proxy.XRequest((byte)RequestType.Connect, Handle, IntPtr.Zero, 0, 0, IntPtr.Zero, 0, IntPtr.Zero, 0, IntPtr.Zero, 0);
}
}
}
public void Disconnect()
{
lock(locker)
{
if (proxy != null)
{
Register(IntPtr.Zero);
//停止底层线程
proxy.XRequest((byte)RequestType.Disconnect, Handle, IntPtr.Zero, 0, 0, IntPtr.Zero, 0, IntPtr.Zero, 0, IntPtr.Zero, 0);
proxy.XRequest((byte)RequestType.Release, Handle, IntPtr.Zero, 0, 0, IntPtr.Zero, 0, IntPtr.Zero, 0, IntPtr.Zero, 0);
proxy.Dispose();
}
proxy = null;
Handle = IntPtr.Zero;
}
}
public void Register(IntPtr ptr1)
{
lock(this)
{
if (proxy != null)
{
proxy.XRequest((byte)RequestType.Register, Handle, IntPtr.Zero, 0, 0, ptr1, 0, IntPtr.Zero, 0, IntPtr.Zero, 0);
}
}
}
}
}