Call JoinableTaskFactory(new JoinableTaskContext()).RunAsync() in InitializeComponent caused designer error
Bug description
Call JoinableTaskFactory(new JoinableTaskContext()).RunAsync() in InitializeComponent caused designer error
Repro steps
Call JoinableTaskFactory(new JoinableTaskContext()).RunAsync() in InitializeComponent caused designer error
private void InitializeComponent()
{
...
TestButton.Click += (sender, e) => _ = new JoinableTaskFactory(new JoinableTaskContext()).RunAsync(() => TestButton_ClickAsync(sender, e));
...
}
Expected behavior
The designer does not error when the event is used in InitializeComponent().
Actual behavior
The designer error when the event was called inside InitializeComponent().
- Version used: Microsoft.VisualStudio.Threading 17.8.14
- Application (if applicable):
Additional context
SOLUTION Move the event outside InitializeComponent() no error appears in the designer.
JoinableTaskContext is supposed to be a singleton in a process. You shouldn't be creating one in an event handler just to call RunAsync.
It looks like you're going to all the trouble just to invoke an async method from an event handler. But what are you gaining for your trouble? Why not just do this:
TestButton.Click += (sender, e) => _ = TestButton_ClickAsync(sender, e);
JoinableTaskContextis supposed to be a singleton in a process. You shouldn't be creating one in an event handler just to callRunAsync.It looks like you're going to all the trouble just to invoke an async method from an event handler. But what are you gaining for your trouble? Why not just do this:
TestButton.Click += (sender, e) => _ = TestButton_ClickAsync(sender, e);
Thank You, What you said also works well. I used the previous one because it was recommended when a warning appeared in the error list window of VS2022