コード例 #1
0
        public MainWindow(Runtime runtime)
        {
            _runtime = runtime;
            _runtime.RegisterExternalThread(UiThread, this.PostWorkItem);
            var logicActor = new GuiMachines.MainWindowLogic();

            logicActor.Window = this;
            Logic             = _runtime.AddActorToThread(UiThread, logicActor);

            Width         = 600;
            FontSize      = 16;
            SizeToContent = System.Windows.SizeToContent.Height;
            Title         = "Actor-based GUI";

            StackPanel rootPanel = new StackPanel();

            rootPanel.Orientation = Orientation.Vertical;
            AddChild(rootPanel);

            GroupBox ioBox         = AddGroupBox(rootPanel, "IO-bound task");
            Button   startIoButton = CreateButton("Download", StartIo);

            _urlEdit = CreateTextBox("http://www.vg.no/");
            FillGroupBox(ioBox, _urlEdit, startIoButton);
            _startIoButton = startIoButton;

            GroupBox cpuBox         = AddGroupBox(rootPanel, "CPU-bound task");
            Button   startCpuButton = CreateButton("Calculate primes", StartCpu);

            _primesEdit = CreateTextBox("10000000");
            FillGroupBox(cpuBox, _primesEdit, startCpuButton);
            _startCpuButton = startCpuButton;

            GroupBox aniBox = AddGroupBox(rootPanel, "Progress");

            _animationControl = new PumpAnimation();
            _animationControl.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            Button cancelButton = CreateButton("Cancel", Cancel);

            cancelButton.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
            _cancelButton = cancelButton;
            FillGroupBox(aniBox, _animationControl, cancelButton);

            _animationControl.Visibility = System.Windows.Visibility.Hidden;
        }
コード例 #2
0
        public void OnMessage_CleanUp_OnSameThread()
        {
            LogActor actor = new LogActor {
                History = _history, FinishTest = _finishTest
            };
            int actorId = _runtime.AddActorToThread("T1", actor);

            _runtime.SendMessage(actorId, 20, null, 4000);
            _finishTest.WaitOne();
            _runtime.RemoveActor(actorId);
            _finishTest.WaitOne();

            CollectionAssert.AreEquivalent(
                new string[] { "OnMessage T1 1 20 4000", "CleanUp T1 1" },
                _history
                );
        }