Esempio n. 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);
        }
Esempio n. 2
0
        public async Task TestForegroundThread(bool initAgain, bool inBg)
        {
            if (initAgain)
            {
                var current = ForegroundThreadAffinitizedObject.CurrentForegroundThreadData;
                if (inBg)
                {
                    await Task.Run(() => { RoslynService.Initialize(); });
                }
                else
                {
                    RoslynService.Initialize();
                }
                Assert.AreSame(current, ForegroundThreadAffinitizedObject.CurrentForegroundThreadData);
            }

            var obj = new ForegroundThreadAffinitizedObject(false);

            // FIXME: Roslyn does not about Xwt Synchronization context.
            //Assert.AreEqual (ForegroundThreadDataKind.MonoDevelopGtk, obj.ForegroundKind);
            Assert.AreEqual(Runtime.MainTaskScheduler, obj.ForegroundTaskScheduler);
            Assert.IsTrue(obj.IsForeground());

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

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

            Assert.AreEqual(1, x);

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

            Assert.AreEqual(2, x);
        }
Esempio n. 3
0
            public CancellableContentControl(ToolTipProvider toolTipProvider, CustomCommitCompletion item)
            {
                Debug.Assert(_foregroundObject.IsForeground());
                _toolTipProvider = toolTipProvider;

                // Set our content to be "..." initially.
                this.Content = toolTipProvider._defaultTextBlock;

                // Kick off the task to produce the new content.  When it completes, call back on
                // the UI thread to update the display.
                var scheduler = TaskScheduler.FromCurrentSynchronizationContext();

                item.GetDescriptionAsync(_cancellationTokenSource.Token)
                .ContinueWith(ProcessDescription, _cancellationTokenSource.Token,
                              TaskContinuationOptions.OnlyOnRanToCompletion, scheduler);

                // If we get unloaded (i.e. the user scrolls down in the completion list and VS
                // dismisses the existing tooltip), then cancel the work we're doing
                this.Unloaded += (s, e) => _cancellationTokenSource.Cancel();
            }