问题
Background: I'm relatively new to C# and UWP and started developing an app in order to learn the basics. I tried searching for an answer of what I assume to be a really basic question, but I wasn't able to find one (probably my fault).
So, the app I'm making is connected to a bluetooth device which streams some data.
The first "view page" is the bluetooth device selection and then it switchs to the main one where I'm going to do everything else. I got event handlers to deal with the incoming streamed data and process/store it.
However I would like to have a "main loop" running which will make some needed manipulations over the data. That being said, I don't really know how to do such a thing.
One way I thought about doing it, is to have a method like the one below, which is called from the class constructor. But I'm not sure this is the best way to go about it.
async void MainLoop()
{
while (true)
{
//do stuff
await Task.Delay(TimeSpan.FromSeconds(X));
}
}
来源:https://stackoverflow.com/questions/40379386/uwp-c-main-loop-event-loop