DispatcherQueue bottleneck in WinUI3

177 views Asked by At

I have a desktop application which has several charts and I should periodically update them using DispatcherQueue. I have a window which shows pictures to the customer. I need to use DispatcherQueue to update pictures in this new window also.

I got a problem there. DispatcherQueue turned into a bottleneck in my application. It seems there is only one instance of DispatcherQueue for each thread and as long as the WinUI application's UI is running under a single thread, I have this issue in all other windows created by the application. which causes a lots of ugly delays in the new window.

Is there any way to create a window in a new thread to get a new DispatcherQueue instance and get rid of this unwelcome lags ?

Sample code:

I have 4 chart (from DevExpress libraries) which are getting updated each 50 milliseconds.

like below:

// RecordingPageViewModel.cs    

Chart1.Data = mainDataSource.Skip(_lastFrame).Take(7500);
DispatcherQueue.TryEnqueue(new DispatcherQueueHandler(() =>
{
    Chart1.UpdateData();
});

Chart2.Data = mainDataSource.Skip(_lastFrame).Take(7500);
DispatcherQueue.TryEnqueue(new DispatcherQueueHandler(() =>
{
    Chart3.UpdateData();
});

// same goes for Chart3 and Chart4

here is the other window, in this window I check something every 100 milli-seconds and on specific conditions I show something to the client let say I show him 1 image every 700 milliseconds:

// CustomerPicturesViewModel.cs

public void ShowNextImage()
{
    // Capture time here.
    DispatcherQueue.TryEnqueue(new DispatcherQueueHandler(() =>
    {
        // Capture time here again (Shows on average 40-60 milli second delay).
        var image = findNextImage();
        CurrentImage = image;
    });
}

additional info: my main application follows WinUI3 template studio structure and I have WindowEx windows.

I just want to run the new window in another thread to decrease the overhead of existing DispatcherQueue on the main application thread.

0

There are 0 answers