async protected static void ReadThread(BluetoothService_test a, System.IO.Stream stm) { while (!cts.IsCancellationRequested) { try { byte[] at = new byte[1024]; Task <int> readTask = stm.ReadAsync(at, 0, 1024); using (cts.Token.Register(() => stm.Close())) { readTask.Wait(cts.Token); int iRead = await readTask; BTMessage msg = new BTMessage(); msg.type = 0; msg.length = iRead; msg.data = at; a.RecvMessage(a, msg); } } catch (System.OperationCanceledException) { //Handle the cancelled task. string text = int.MaxValue.ToString(); } catch (System.Exception e) { string text = e.ToString(); } } }
async private void PhaserThread(BluetoothService_test service) { while (!service.que.isEmpty()) { byte getMethod = service.que.DeQueue(); await Task.Delay(100); switch (getMethod) { case 0x00: break; case 0x02: { byte caseSwitch2 = service.que.DeQueue(); //send MSR data if (caseSwitch2 >= 0x43 && caseSwitch2 <= 0x47) { service.phasingMSRdata(caseSwitch2); } else { byte[] tempData = new byte[2]; tempData[0] = getMethod; tempData[1] = caseSwitch2; service.passingUnKownData(tempData); } } break; case 0x1B: { byte[] tempData = new byte[1]; tempData[0] = getMethod; service.passingUnKownData(tempData); } break; default: { //일반 응답 데이터 전달 byte[] testa = new byte[1]; testa[0] = getMethod; service.passingUnKownData(testa); } break; } } service.ThreadPhaser = null; }