Exemplo n.º 1
0
        public async Task CheckObjectThread_Heartbeat()
        {
            List <int> tickDurations = new List <int>();

            ObjectThread objThread         = new ObjectThread("TestThread_Heartbeat", 500);
            Exception    occurredException = null;

            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                objThread.Tick += (sender, eArgs) =>
                {
                    tickDurations.Add((int)stopwatch.Elapsed.TotalMilliseconds);

                    stopwatch.Reset();
                    stopwatch.Start();
                };
                objThread.Start();

                // Wait some thime since we have some heartbeats
                await Task.Delay(2500);
            }
            catch (Exception ex) { occurredException = ex; }

            // Wait for thread finish
            await objThread.StopAsync(1000);

            // Check results
            Assert.Null(occurredException);
            Assert.True(tickDurations.Count > 4);
            Assert.True(tickDurations.Count < 10);
            Assert.True(tickDurations
                        .Count((actInt) => actInt > 450 && actInt < 550) > 4);
        }
Exemplo n.º 2
0
        public async Task WinForms_Parent_Child_Switch()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

            Panel hostPanel1 = null;
            Panel hostPanel2 = null;
            SeeingSharpRendererControl renderControl = null;
            int       stepID = 0;
            Exception fakeUIThreadException = null;

            ObjectThread fakeUIThread = new ObjectThread("Fake-UI", 100);

            fakeUIThread.ThreadException += (sender, eArgs) =>
            {
                fakeUIThreadException = eArgs.Exception;
            };
            fakeUIThread.Starting += (sender, eArgs) =>
            {
                hostPanel1      = new System.Windows.Forms.Panel();
                hostPanel1.Size = new Size(500, 500);
                hostPanel2      = new System.Windows.Forms.Panel();
                hostPanel2.Size = new Size(500, 500);

                renderControl      = new SeeingSharpRendererControl();
                renderControl.Dock = System.Windows.Forms.DockStyle.Fill;

                hostPanel1.CreateControl();
                hostPanel2.CreateControl();
                hostPanel1.Controls.Add(renderControl);
            };
            fakeUIThread.Tick += (sender, eArgs) =>
            {
                Application.DoEvents();
                stepID++;

                switch (stepID)
                {
                case 2:
                    hostPanel1.Controls.Remove(renderControl);
                    break;

                case 4:
                    hostPanel2.Controls.Add(renderControl);
                    break;

                case 8:
                    hostPanel2.Controls.Remove(renderControl);
                    break;

                case 10:
                    renderControl.Dispose();
                    hostPanel2.Dispose();
                    hostPanel1.Dispose();
                    break;

                case 11:
                    fakeUIThread.Stop();
                    break;
                }
            };
            fakeUIThread.Start();

            // Wait until the Fake-UI thread stopped
            await fakeUIThread.WaitUntilSoppedAsync();

            // Some checks after rendering
            Assert.True(GraphicsCore.Current.MainLoop.IsRunning);
            Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0);
            Assert.Null(fakeUIThreadException);
            Assert.True(renderControl.IsDisposed);
        }
Exemplo n.º 3
0
        public async Task WinForms_Parent_Child_Switch()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            // Ensure that any async disposal is  done before we create a new GraphicsCore
            await GraphicsCore.Current.MainLoop !.WaitForNextPassedLoopAsync();
            await GraphicsCore.Current.MainLoop !.WaitForNextPassedLoopAsync();

            Panel?hostPanel1 = null;
            Panel?hostPanel2 = null;
            SeeingSharpRendererControl?renderControl = null;
            var       stepId = 0;
            Exception?fakeUIThreadException = null;

            var fakeUIThread = new ObjectThread("Fake-UI", 100);

            fakeUIThread.ThreadException += (_, eArgs) =>
            {
                fakeUIThreadException = eArgs.Exception;
            };
            fakeUIThread.Starting += (_, _) =>
            {
                hostPanel1 = new Panel
                {
                    Size = new GDI.Size(500, 500)
                };

                hostPanel2 = new Panel
                {
                    Size = new GDI.Size(500, 500)
                };

                renderControl = new SeeingSharpRendererControl
                {
                    Dock = DockStyle.Fill
                };

                hostPanel1.CreateControl();
                hostPanel2.CreateControl();
                hostPanel1.Controls.Add(renderControl);
            };
            fakeUIThread.Tick += (_, _) =>
            {
                Application.DoEvents();
                stepId++;

                switch (stepId)
                {
                case 2:
                    hostPanel1 !.Controls.Remove(renderControl !);
                    break;

                case 4:
                    hostPanel2 !.Controls.Add(renderControl !);
                    break;

                case 8:
                    hostPanel2 !.Controls.Remove(renderControl !);
                    break;

                case 10:
                    renderControl !.Dispose();
                    hostPanel2 !.Dispose();
                    hostPanel1 !.Dispose();
                    break;

                case 20:
                    fakeUIThread.Stop();
                    break;
                }
            };
            fakeUIThread.Start();

            // Wait until the Fake-UI thread stopped
            await fakeUIThread.WaitUntilSoppedAsync();

            // Some checks after rendering
            Assert.IsTrue(GraphicsCore.Current.MainLoop.IsRunning);
            Assert.IsTrue(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0);
            Assert.IsNull(fakeUIThreadException);
            Assert.IsTrue(renderControl !.IsDisposed);
        }