Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
415 views
in Technique[技术] by (71.8m points)

c# - UWP update UI from Task

I have application, which is checking network ranges (for running http service) in local network.

So it means, that I am checking f.e. from 10.0.0.1 to 10.0.0.255. And here is the problem, when running on PC, the speed is enough, but when running on Lumia 950 the speed is not enough. So I would like to update the UI during the scan.

So here are the questions:

  1. At this moment I have several tasks f.e. 10 - every task is scanning his range f.e. task 1 - 10.0.0.1 to 10.0.0.25 etc.. - should I use 10 tasks or is there some way, how the .net will solve it itself? What will be the performance, f.e. if I will use 50 tasks?

  2. Second question is, during the scan I will find the PC, where the web service is working, but... How should I update the UI when the PC is found? At this moment I am only able to do it, when all tasks are finished..

The methods I am calling are async Tasks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  1. You can use as many tasks as you want, the system will automatically perform queuing and execution for you. That's one of the advantages of using the built in mechanisms

  2. To execute code on the UI thread you can use the dispatcher like this:

    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => {
                //UI code here
    });
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...