Skip to content

Commit

Permalink
Deprecate and remove InvokeAsyncDoNotUseInNewCode
Browse files Browse the repository at this point in the history
Rewrite the callsite to use `InvokeAsync` instead, that switches
the execution context to the UI thread.

Closes gitextensions#6799
  • Loading branch information
RussKie committed Jun 24, 2019
1 parent dd4a052 commit 68b6f66
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 28 deletions.
3 changes: 1 addition & 2 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ protected override void OnLoad(EventArgs e)

protected override void OnActivated(EventArgs e)
{
this.InvokeAsyncDoNotUseInNewCode(OnActivate);
this.InvokeAsync(OnActivate).FileAndForget();
base.OnActivated(e);
}

Expand Down Expand Up @@ -949,7 +949,6 @@ void ShowRevisions()
private void OnActivate()
{
CheckForMergeConflicts();

return;

void CheckForMergeConflicts()
Expand Down
26 changes: 0 additions & 26 deletions GitUI/GitUIExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,32 +215,6 @@ public static async Task InvokeAsync<T>(this Control control, Action<T> action,
action(state);
}

#pragma warning disable VSTHRD100 // Avoid async void methods
/// <summary>
/// Use <see cref="InvokeAsync(Control, Action, CancellationToken)"/> instead. If the result of
/// <see cref="InvokeAsync(Control, Action, CancellationToken)"/> is not awaited, use
/// <see cref="ThreadHelper.FileAndForget(Task, Func{Exception, bool})"/> to ignore it.
/// </summary>
public static async void InvokeAsyncDoNotUseInNewCode(this Control control, Action action)
#pragma warning restore VSTHRD100 // Avoid async void methods
{
if (ThreadHelper.JoinableTaskContext.IsOnMainThread)
{
await Task.Yield();
}
else
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
}

if (control.IsDisposed)
{
return;
}

action();
}

public static void InvokeSync(this Control control, Action action)
{
ThreadHelper.JoinableTaskFactory.Run(
Expand Down

0 comments on commit 68b6f66

Please sign in to comment.