Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 28d61dd

Browse files
authored
Merge pull request #340 from github-for-unity/fixes/ui-thread-check-of-doom
Fix ui thread check
2 parents 8ea6ea8 + d3f3aeb commit 28d61dd

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public ApplicationManagerBase(SynchronizationContext synchronizationContext)
1717
{
1818
SynchronizationContext = synchronizationContext;
1919
SynchronizationContext.SetSynchronizationContext(SynchronizationContext);
20-
ThreadingHelper.SetMainThread();
20+
ThreadingHelper.SetUIThread();
2121
UIScheduler = TaskScheduler.FromCurrentSynchronizationContext();
2222
ThreadingHelper.MainThreadScheduler = UIScheduler;
2323
TaskManager = new TaskManager(UIScheduler);

src/GitHub.Api/Threading/ThreadingHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ static class ThreadingHelper
1010
public static TaskScheduler MainThreadScheduler { get; set; }
1111

1212
public static int MainThread { get; set; }
13-
public static bool InMainThread { get { return MainThread == 0 || Thread.CurrentThread.ManagedThreadId == MainThread; } }
13+
static bool InMainThread { get { return MainThread == 0 || Thread.CurrentThread.ManagedThreadId == MainThread; } }
1414

15-
public static void SetMainThread()
15+
public static void SetUIThread()
1616
{
1717
MainThread = Thread.CurrentThread.ManagedThreadId;
1818
}
1919

20-
public static bool InUIThread => (!Guard.InUnitTestRunner && InMainThread) || !(Guard.InUnitTestRunner);
20+
public static bool InUIThread => InMainThread || Guard.InUnitTestRunner;
2121

2222
/// <summary>
2323
/// Switch to the UI thread
@@ -97,7 +97,7 @@ public bool IsCompleted
9797
{
9898
get
9999
{
100-
return (this.scheduler == TaskManager.Instance.UIScheduler && InMainThread) || (this.scheduler != TaskManager.Instance.UIScheduler && !InMainThread);
100+
return (this.scheduler == TaskManager.Instance.UIScheduler && InUIThread) || (this.scheduler != TaskManager.Instance.UIScheduler && !InUIThread);
101101
}
102102
}
103103

0 commit comments

Comments
 (0)