public static bool OnDeviceAttached(AMDevice device) { WaitCallback waitCallback = new WaitCallback(WorkItem); ThreadPool.QueueUserWorkItem(waitCallback, device); return(true); }
public static void WorkItem(object state) { task++; AMDevice device = state as AMDevice; Run(device); task--; }
public static bool Run(AMDevice device) { try { if (!device.Connect()) { device.WriteLine("Connect error"); return(false); } if (!device.ValidatePairing()) { Thread.Sleep(15); } if (!device.ValidatePairing()) { Thread.Sleep(15); } if (!device.ValidatePairing()) { device.WriteLine("Pairing error"); device.Disconnect(); return(false); } if (!device.StartSession()) { device.WriteLine("Session error"); device.Disconnect(); return(false); } Hashtable args = Program.inArgs; string ca = args["command"] as string; string pa = args["param"] as string; Task task = new Task(device); task.Execute(ca, pa); device.StopSession(); device.Disconnect(); device.WriteLine("Execute success"); return(true); } catch (Exception e) { device.WriteLine(e.Message); return(false); } }