Beispiel #1
0
        public async Task TestForegroundThread(bool inBg)
        {
            var context = CompositionManager.Instance.GetExportedValue <IThreadingContext> ();
            var obj     = new ForegroundThreadAffinitizedObject(context, false);

            var roslynContext = obj.ThreadingContext.JoinableTaskContext;

            Assert.AreSame(Runtime.MainThread, roslynContext.MainThread);
            Assert.IsTrue(obj.IsForeground());

            await Task.Run(() => {
                Assert.IsFalse(obj.IsForeground());
            });

            int x = 0;
            await obj.InvokeBelowInputPriorityAsync(() => {
                Assert.IsTrue(obj.IsForeground());
                x++;
            });

            Assert.AreEqual(1, x);

            await Task.Run(() => obj.InvokeBelowInputPriorityAsync(() => {
                Assert.IsTrue(obj.IsForeground());
                x++;
            }));

            Assert.AreEqual(2, x);
        }