Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace MainApp
- {
- public partial class Form1 : Form
- {
- public static Server socket = null;
- public static ManualResetEvent _shutdownEvent;
- public static Thread _thread, thread2;
- public Form1()
- {
- InitializeComponent();
- }
- public class Server : WebSocketBehavior
- {
- Form1 frm = new Form1();
- FingerprintServer.Form1 fp = new FingerprintServer.Form1();
- TimeSpan waitTime = new TimeSpan(0, 0, 7);
- DateTime waitUntil;
- CancellationTokenSource cancelTokenSource = new CancellationTokenSource();
- CancellationToken token = new CancellationToken();
- Task task2;
- protected override void OnMessage(MessageEventArgs e)
- {
- var msg = e.Data;
- waitUntil = DateTime.Now + waitTime;
- switch (msg)
- {
- case "InitScanner":
- //fp.StopBiometricScanner();
- msg = FingerprintServer.Form1.InitBiometricScanner();
- Send(msg);
- break;
- case "StartScanning":
- task2 = Task.Factory.StartNew(() =>
- {
- while (DateTime.Now < waitUntil)
- {
- if (token.IsCancellationRequested)
- {
- Console.WriteLine("Операция прервана");
- return;
- }
- Send(fp.DoWork());
- }
- });
- break;
- case "StopScanning":
- cancelTokenSource.Cancel(); //по вэб сокету приходит флаг StopScanning. Но он не хочет останавливать поток
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement