Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Slow down simulated main thread queue for marshaling tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hartez committed Jul 22, 2020
1 parent 53cbcac commit 9c8aa96
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Reflection;
Expand Down Expand Up @@ -50,7 +51,6 @@ public async Task AddOffUIThread()
// Add an item from a threadpool thread
await Task.Run(() =>
{
var x = Thread.CurrentThread.ManagedThreadId;
source.Add(1);
countFromThreadPool = moc.Count;
});
Expand Down Expand Up @@ -232,12 +232,11 @@ class MarshalingTestPlatformServices : IPlatformServices
{
int _threadId;
bool _running;
BlockingCollection<Action> _todo = new BlockingCollection<Action>();
Queue<Action> _todo = new Queue<Action>();

public void Stop()
{
_running = false;
_todo.CompleteAdding();
}

public void Start()
Expand All @@ -254,7 +253,11 @@ public void Start()
{
try
{
_todo.Take()?.Invoke();
Thread.Sleep(100);
while (_todo.Count > 0)
{
_todo.Dequeue().Invoke();
}
}
catch (Exception ex)
{
Expand All @@ -268,7 +271,7 @@ public void Start()

public void BeginInvokeOnMainThread(Action action)
{
_todo.Add(action);
_todo.Enqueue(action);
}

public OSAppTheme RequestedTheme { get; }
Expand Down

0 comments on commit 9c8aa96

Please sign in to comment.