-
Notifications
You must be signed in to change notification settings - Fork 0
/
Listener.cs
44 lines (36 loc) · 878 Bytes
/
Listener.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
using System;
namespace WindowsUsb {
public class UsbListener {
private string usbHash;
private Func<string> callback;
public UsbListener(string usbHash, Func<string> callback){
if(usbHash == null){
throw new System.ArgumentException("Argument cannot be null.", "usbHash");
}
if(callback == null){
throw new System.ArgumentException("Argument cannot be null.", "callback");
}
this.usbHash = usbHash;
this.callback = callback;
}
public void start(){
bool connected;
bool alreadyNotify = false;
while(true){
connected = false;
foreach(UsbStore usb in UsbStoreProvider.getAllUsbStore()){
if(usbHash == usb.getHash()){
connected = true;
if(!alreadyNotify){
alreadyNotify = true;
callback();
}
}
}
if(!connected){
alreadyNotify = false;
}
}
}
}
}