C# WPF - Tasks vs Multithreading, and updating UI components from them

前端 未结 3 1942
忘掉有多难
忘掉有多难 2021-01-23 02:11

So basically I\'m using C# to write a port scanning WPF application, that will scan over a thousand combinations of ports and IPs (x.x.x.x:xx). As a result, I have to split this

3条回答
  •  被撕碎了的回忆
    2021-01-23 02:46

    I think BackgroundWorker is better choice. In WPF, you are not allowed to make changes to the UI from another thread. So, simply moving code in the event handler method causes a problem when reflecting process result on UI (e.g. showing message "done").

    It is still the same in BackgroundWorker.DoWork, but BackgroundWorker's ReportProgress and RunWorkerCompleted can help you to have your code simple. Have a look at the answer here. I think you can get the point easily.

提交回复
热议问题