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

Fix ui thread check #340

Merged
merged 1 commit into from
Sep 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/GitHub.Api/Application/ApplicationManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ApplicationManagerBase(SynchronizationContext synchronizationContext)
{
SynchronizationContext = synchronizationContext;
SynchronizationContext.SetSynchronizationContext(SynchronizationContext);
ThreadingHelper.SetMainThread();
ThreadingHelper.SetUIThread();
UIScheduler = TaskScheduler.FromCurrentSynchronizationContext();
ThreadingHelper.MainThreadScheduler = UIScheduler;
TaskManager = new TaskManager(UIScheduler);
Expand Down
8 changes: 4 additions & 4 deletions src/GitHub.Api/Threading/ThreadingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ static class ThreadingHelper
public static TaskScheduler MainThreadScheduler { get; set; }

public static int MainThread { get; set; }
public static bool InMainThread { get { return MainThread == 0 || Thread.CurrentThread.ManagedThreadId == MainThread; } }
static bool InMainThread { get { return MainThread == 0 || Thread.CurrentThread.ManagedThreadId == MainThread; } }

public static void SetMainThread()
public static void SetUIThread()
{
MainThread = Thread.CurrentThread.ManagedThreadId;
}

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

/// <summary>
/// Switch to the UI thread
Expand Down Expand Up @@ -97,7 +97,7 @@ public bool IsCompleted
{
get
{
return (this.scheduler == TaskManager.Instance.UIScheduler && InMainThread) || (this.scheduler != TaskManager.Instance.UIScheduler && !InMainThread);
return (this.scheduler == TaskManager.Instance.UIScheduler && InUIThread) || (this.scheduler != TaskManager.Instance.UIScheduler && !InUIThread);
}
}

Expand Down