public async Task ClearAsync() { await RunOnUIThread.RunAsync(() => { RemoveExistingInfoBar(); }); }
public async Task ShowAsync(Guid toolWindowId) { await RunOnUIThread.RunAsync(() => { RemoveExistingInfoBar(); AddInfoBar(toolWindowId); }); }
public async Task RunAsync_StartsOnUIThread_ExecuteOnUIThread() { bool operationExecuted = false; using var hackedThreadingScope = new HackedVSThreadingScope(); // Act await RunOnUIThread.RunAsync(() => operationExecuted = true); operationExecuted.Should().BeTrue(); hackedThreadingScope.CheckThreadSwitchNotRequested(); }
public async Task RunAsync_StartsOnUIThread_ExecuteOnUIThread() { ThreadHelper.SetCurrentThreadAsUIThread(); var initialThread = Thread.CurrentThread.ManagedThreadId; int executionThreadId = -1; // Act await RunOnUIThread.RunAsync(() => executionThreadId = Thread.CurrentThread.ManagedThreadId); executionThreadId.Should().Be(initialThread); Thread.CurrentThread.ManagedThreadId.Should().Be(initialThread); // should still be on the "UI" thread }
public async Task RunAsync_StartsOnBackgroundThread_ExecuteOnUIThread() { bool operationExecuted = false; using var hackedThreadingScope = new HackedVSThreadingScope(); // Act await Task.Run(async() => { // Now on a background thread, so expecting the VS to request a switch to the main thread await RunOnUIThread.RunAsync(() => operationExecuted = true); }); operationExecuted.Should().BeTrue(); hackedThreadingScope.CheckThreadSwitchRequested(); }