WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

DispatcherQueue.TryEnQueue() will execute the callback multiple times

Open zxmfzx opened this issue 1 year ago • 1 comments

Describe the bug

TextBox.Text += string in a sub-thread (created using the Thread class) using the DispatcherQueue.TryEnQueue() function then this string will be added multiple times. Using a breakpoint, I found that the re-callback, i.e., the Lambda function, was executed multiple times, but TryEnQueue() was executed only once

Steps to reproduce the bug

parent.DispatcherQueue.TryEnqueue( () => {

        parent.text_log.Text += "ABCDEFGHI" 
            + System.Environment.NewLine;
}
);

Expected behavior

The callback should only run once

Screenshots

No response

NuGet package version

None

Packaging type

No response

Windows version

No response

IDE

No response

Additional context

No response

zxmfzx avatar Jan 17 '24 03:01 zxmfzx

I personally don't see this.

While it is a C++ application, the code that I used was:

    void MainWindow::Click_Click(winrt::IInspectable const &, winrt::RoutedEventArgs const &)
    {
        std::thread t([this]()
            {
                auto dq = DispatcherQueue();
                dq.TryEnqueue([this]()
                    {
                        auto current_text = OutText().Text();
                        OutText().Text(current_text + L"ABCDEF");
                    });
            });

        t.detach();
    }

This was a regular WinUI 3 application.

https://github.com/microsoft/WindowsAppSDK/assets/52577874/23f100f2-cbef-417f-828d-58b5b68f0e00

You can see from this video that it only appends the text once. Could you provide a sample that reproduces this problem?

DarranRowe avatar Jan 17 '24 19:01 DarranRowe

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment.