//*********************************** //*********************************** //********** RECEIVE BYTES ********** //*********************************** //*********************************** //This is all a bit complex....but necessary if you want receive to happen asynchrously and for your app to be notified instead of your code having to poll it (this code is basically polling it to create a receive event) //ASYNC METHOD TO CREATE THE LISTEN LOOP public async Task <int> StartReceive() { ReadCancellationTokenSource = new CancellationTokenSource(); GPIOInterface theDevice = GPIOInterface.Instance; theDevice.FlashLed(1, 10); while (true) { await Listen().ConfigureAwait(false); if ((ReadCancellationTokenSource.Token.IsCancellationRequested) || (UartPort == null)) { break; } } return(await Task.FromResult(0)); }
public void Run(IBackgroundTaskInstance taskInstance) { // // TODO: Insert code to perform background work theDevice = GPIOInterface.Instance; mrSound = new SoftSynth(); mrMidi = new MidiUtils(); var xx = mrMidi.Initialize(); xx.Wait(); mrMidi.RegisterChannelCallback(0, HandleMidiMessage); var yy = mrMidi.StartReceive(); // If you start any asynchronous methods here, prevent the task // from closing prematurely by using BackgroundTaskDeferral as // described in http://aka.ms/backgroundtaskdeferral //theDevice.Dispose(); }