WPF GUI Performance with a large number of parallel tasks

后端 未结 3 505
清歌不尽
清歌不尽 2021-01-28 07:23

I developed a small client (WPF) to make some stress test on our systems. Essentially it has to call various methods on an Asp.Net WebApi endpoint in parallel.

Each time

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-28 07:47

    My first question is: why opening one instance with x tasks is worse in terms of responsivness than opening n instances with x/n tasks?

    Possibly because you are getting more events to handle on the UI thread. I guess your ErrorBetCountChanged, GoodRequestCountChanged and TryRequestCountChanged event handlers are invoked on the UI thread and a lot of events being raised may flood the UI thread.

    As Gusdor suggets you should probably find a way of batching the updates. Take a look at the reactive extensions (Rx): http://www.introtorx.com/content/v1.0.10621.0/01_WhyRx.html.

    It has a Buffer method that may come in handy: http://www.introtorx.com/content/v1.0.10621.0/13_TimeShiftedSequences.html.

    It also has en Obervable.FromEvent method that you can use to convert an event into an IObservable: https://msdn.microsoft.com/en-us/library/hh229241(v=vs.103).aspx.

    My second questions is: how can I address the problem to make everything work on a single GUI?

    You need to find a way - one or anoher - of updating the UI less frequently. Batching the updates and events should be a good starting point. Raising less notifications is another option. Maybe you need to both.

提交回复
热议问题