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

Commit 9c8aa96

Browse files
committed
Slow down simulated main thread queue for marshaling tests
1 parent 53cbcac commit 9c8aa96

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Xamarin.Forms.Core.UnitTests/MarshalingObservableCollectionTests.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Concurrent;
3+
using System.Collections.Generic;
34
using System.Collections.ObjectModel;
45
using System.IO;
56
using System.Reflection;
@@ -50,7 +51,6 @@ public async Task AddOffUIThread()
5051
// Add an item from a threadpool thread
5152
await Task.Run(() =>
5253
{
53-
var x = Thread.CurrentThread.ManagedThreadId;
5454
source.Add(1);
5555
countFromThreadPool = moc.Count;
5656
});
@@ -232,12 +232,11 @@ class MarshalingTestPlatformServices : IPlatformServices
232232
{
233233
int _threadId;
234234
bool _running;
235-
BlockingCollection<Action> _todo = new BlockingCollection<Action>();
235+
Queue<Action> _todo = new Queue<Action>();
236236

237237
public void Stop()
238238
{
239239
_running = false;
240-
_todo.CompleteAdding();
241240
}
242241

243242
public void Start()
@@ -254,7 +253,11 @@ public void Start()
254253
{
255254
try
256255
{
257-
_todo.Take()?.Invoke();
256+
Thread.Sleep(100);
257+
while (_todo.Count > 0)
258+
{
259+
_todo.Dequeue().Invoke();
260+
}
258261
}
259262
catch (Exception ex)
260263
{
@@ -268,7 +271,7 @@ public void Start()
268271

269272
public void BeginInvokeOnMainThread(Action action)
270273
{
271-
_todo.Add(action);
274+
_todo.Enqueue(action);
272275
}
273276

274277
public OSAppTheme RequestedTheme { get; }

0 commit comments

Comments
 (0)