Dev2.Core.Tests.ThreadExecuter.RunCodeAsSTA C# (CSharp) Method

RunCodeAsSTA() public static method

public static RunCodeAsSTA ( AutoResetEvent are, ThreadStart originalDelegate ) : void
are System.Threading.AutoResetEvent
originalDelegate ThreadStart
return void
        public static void RunCodeAsSTA(AutoResetEvent are, ThreadStart originalDelegate)
        {
            Thread thread = new Thread(delegate()
            {
                try
                {
                    originalDelegate.Invoke();
                    are.Set();
                    Dispatcher.CurrentDispatcher.InvokeShutdown();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    are.Set();
                }
            });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }

Usage Example

Beispiel #1
0
        public void FilteredNavigationViewModel_WhereFilterReset_Expects_OriginalExpandState()
        {
            IExplorerItemModel resourceVM = null;

            var reset = new AutoResetEvent(false);

            ThreadExecuter.RunCodeAsSTA(reset,
                                        () =>
            {
                Init(false, true);
                resourceVM = _vm.FindChild(_mockResourceModel.Object);
                IExplorerItemModel resourceVM2_1 = _vm.FindChild(_mockResourceModel1.Object);
                IExplorerItemModel resourceVM2_2 = _vm.FindChild(_mockResourceModel2.Object);

                Assert.IsTrue(resourceVM.Parent.IsExplorerExpanded == false);
                Assert.IsTrue(resourceVM2_1.Parent.IsExplorerExpanded == false);
                Assert.IsTrue(resourceVM2_2.Parent.IsExplorerExpanded == false);

                _vm.UpdateSearchFilter("Mock2");

                _vm.UpdateSearchFilter("");
            });
            reset.WaitOne();

            Assert.IsTrue(resourceVM.Parent.IsExplorerExpanded == false);
        }
ThreadExecuter