-
Couldn't load subscription status.
- Fork 1.1k
Closed
Labels
area-Analyzers/CodeFixesA Roslyn Analyzer is either needed for the context, needs to be scope extended or fixed.A Roslyn Analyzer is either needed for the context, needs to be scope extended or fixed.
Description
There are 2 ways to use InvokeAsync - from the outside, which always needs explicit member access, and from the inside, which can be using explicit member access (this or Me in VB), but usually, we do not do it and use it implicitly. Inside most Microsoft repos, .editorconfig is even configures to make the explicit usage where implicit is possible an error (see code sample below).
For the implicit member access, the WFO2001 Analyzer is not being triggered.
// Example 1: Explicit member access (control.InvokeAsync)
private async void UpdateButtonFromBackgroundThread()
{
var result = await Task.Run(() => PerformLongRunningOperation())
.ConfigureAwait(false);
// Explicit access is necessary - we need to define the instance.
>>> await button1.InvokeAsync(() => {
button1.Text = result;
button1.Enabled = true;
});
}
// Example 2: Implicit use from within a Form
private async void MyForm_Load(object sender, EventArgs e)
{
var data = await Task.Run(() => FetchDataFromDatabase())
.ConfigureAwait(false);
// .editorconfig is often configured to have including this/me causing an error.
// We have to InvokeAsync often as implicit member access.
>>> await [this.]InvokeAsync(() => {
dataGridView1.DataSource = data;
statusLabel.Text = "Data loaded successfully";
});
}Metadata
Metadata
Assignees
Labels
area-Analyzers/CodeFixesA Roslyn Analyzer is either needed for the context, needs to be scope extended or fixed.A Roslyn Analyzer is either needed for the context, needs to be scope extended or fixed.