UWP (c#): Main Loop (Event loop)

风格不统一 提交于 2019-12-11 06:57:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!