private async void button24_Click(object sender, EventArgs e) { string dev_name = textBox3.Text.ToString(); string characteristic_name = "EnvironmentalSensing/Temperature"; listStatus.Items.Add($"set {characteristic_name}"); var error_code = await ble2.ReadCharacteristic(dev_name, characteristic_name); listStatus.Items.Add($"ErrorCode: {error_code}"); if (error_code == ERROR_CODE.NONE) { listStatus.Items.Add($"{characteristic_name}: {ble2.getCharacteristic()}"); } }
private async void RunTask(TaskName taskName, string arg1, string arg2, Action <ERROR_CODE> callback) { // 비동기로 Worker Thread에서 도는 task1 // Task.Run(): .NET Framework 4.5+ ERROR_CODE result = ERROR_CODE.NONE; switch (taskName) { case TaskName.OPEN_DEVICE: result = await ble.OpenDevice(arg1); listStatus.Items.Add($"ErrorCode: {result}"); break; case TaskName.SET_SERVICE: //task1 = Task.Run(() => bleservice.SetService(deviceName)); //result = await task1; result = await ble.SetService(arg2); listStatus.Items.Add($"ErrorCode: {result}"); break; case TaskName.READ_CHARACTERISTIC: var resultString = await ble.ReadCharacteristic(arg1, arg2); listStatus.Items.Add($"{resultString}"); break; } callback(result); }