• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# ApartmentState类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ApartmentState的典型用法代码示例。如果您正苦于以下问题:C# ApartmentState类的具体用法?C# ApartmentState怎么用?C# ApartmentState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ApartmentState类属于命名空间,在下文中一共展示了ApartmentState类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: DispatcherContext

 /// <summary>
 /// Initialies a new <see cref="DispatcherContext"/> synchronized with a new <see cref="Thread"/> instance
 /// </summary>
 /// <param name="threadApartmentState">The <see cref="ApartmentState"/> of the <see cref="Dispatcher"/>'s <see cref="Thread"/></param>
 ///<param name="owner">The <see cref="Dispatcher"/> that owns the <see cref="DispatcherContext"/></param>
 public DispatcherContext(Dispatcher owner, ApartmentState threadApartmentState)
 {
     Thread dispatcherThread;
     this.Owner = owner;
     dispatcherThread = new Thread(new ParameterizedThreadStart(this.ExecuteOperations));
     dispatcherThread.SetApartmentState(threadApartmentState);
 }
开发者ID:yonglehou,项目名称:Photon,代码行数:12,代码来源:DispatcherContext.cs


示例2: SingleThreadTaskScheduler

		public SingleThreadTaskScheduler(string name = null, ThreadPriority priority = ThreadPriority.Normal, ApartmentState apartmentState = ApartmentState.STA)
		{
#if DEBUG
			_allocStackTrace = new StackTrace();
#endif

			_thread = new Thread(
				() =>
				{
					try
					{
						foreach (var task in _queue.GetConsumingEnumerable())
							TryExecuteTask(task);
					}
					finally
					{
						_queue.Dispose();
					}
				});

			_thread.IsBackground = true;
			_thread.Name = name;
			_thread.Priority = priority;
			_thread.SetApartmentState(apartmentState);

			_thread.Start();
		}
开发者ID:slorion,项目名称:nlight,代码行数:27,代码来源:SingleThreadTaskScheduler.cs


示例3: Run

        private void Run(ThreadStart userDelegate, ApartmentState apartmentState)
        {
            lastException = null;

            var thread = new Thread(
                delegate()
                    {
                        try
                        {
                            userDelegate.Invoke();
                        }
                        catch (Exception e)
                        {
                            lastException = e;
                        }
                    });
            thread.SetApartmentState(apartmentState);

            thread.Start();
            thread.Join();

            if (ExceptionWasThrown())
            {
                ThrowExceptionPreservingStack(lastException);
            }
        }
开发者ID:Jeff-Lewis,项目名称:nhaml,代码行数:26,代码来源:CrossThreadTestRunner.cs


示例4: AssemblyItem

		public AssemblyItem( string path, ApartmentState apartment )
		{
			if ( !System.IO.Path.IsPathRooted( path ) )
				throw new ArgumentException( "Assembly path must be absolute", "path" );
			this.path = path;
			this.apartment = apartment;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:7,代码来源:AssemblyItem.cs


示例5: StartNewDispatcherThread

        private void StartNewDispatcherThread(ApartmentState apartmentState)
        {
            var reset = new ManualResetEvent(false);

            var t = new Thread((ThreadStart)delegate
            {
                Thread.CurrentThread.Name = string.Format("WorkDispatcherThread");

                Dispatcher.Run(reset);
            })
            {
                IsBackground = true
            };

            t.SetApartmentState(apartmentState);

            t.Priority = ThreadPriority.Normal;

            /* Starts the thread and creates the object */
            t.Start();
           
            /* We wait until our dispatcher is initialized and
             * the new Dispatcher is running */
            reset.WaitOne();
        }
开发者ID:jiailiuyan,项目名称:WPF-MediaKit,代码行数:25,代码来源:WorkDispatcherObject.cs


示例6: GetParentThreadInfo

        public void GetParentThreadInfo()
        {
            ParentThread = Thread.CurrentThread;
#if !NETCF
            ParentThreadApartment = GetApartmentState(ParentThread);
#endif
        }
开发者ID:JohanLarsson,项目名称:nunit,代码行数:7,代码来源:ThreadingTests.cs


示例7: WorkerThread

 protected WorkerThread(string name, ThreadPriority priority, ApartmentState apartmentState)
 {
     _thread = new Thread(new ThreadStart(this.InternalRun));
     _thread.Name = name;
     _thread.Priority = priority;
     _thread.SetApartmentState(apartmentState);
 }
开发者ID:dot-i,项目名称:ARGUS-TV-Clients,代码行数:7,代码来源:WorkerThread.cs


示例8: ServerSteppablePipelineDriver

 internal ServerSteppablePipelineDriver(PowerShell powershell, bool noInput, Guid clientPowerShellId, Guid clientRunspacePoolId, ServerRunspacePoolDriver runspacePoolDriver, ApartmentState apartmentState, HostInfo hostInfo, System.Management.Automation.RemoteStreamOptions streamOptions, bool addToHistory, Runspace rsToUse, ServerSteppablePipelineSubscriber eventSubscriber, PSDataCollection<object> powershellInput)
 {
     this.localPowerShell = powershell;
     this.clientPowerShellId = clientPowerShellId;
     this.clientRunspacePoolId = clientRunspacePoolId;
     this.remoteStreamOptions = streamOptions;
     this.apartmentState = apartmentState;
     this.noInput = noInput;
     this.addToHistory = addToHistory;
     this.eventSubscriber = eventSubscriber;
     this.powershellInput = powershellInput;
     this.input = new PSDataCollection<object>();
     this.inputEnumerator = this.input.GetEnumerator();
     this.input.ReleaseOnEnumeration = true;
     this.dsHandler = runspacePoolDriver.DataStructureHandler.CreatePowerShellDataStructureHandler(clientPowerShellId, clientRunspacePoolId, this.remoteStreamOptions, null);
     this.remoteHost = this.dsHandler.GetHostAssociatedWithPowerShell(hostInfo, runspacePoolDriver.ServerRemoteHost);
     this.dsHandler.InputEndReceived += new EventHandler(this.HandleInputEndReceived);
     this.dsHandler.InputReceived += new EventHandler<RemoteDataEventArgs<object>>(this.HandleInputReceived);
     this.dsHandler.StopPowerShellReceived += new EventHandler(this.HandleStopReceived);
     this.dsHandler.HostResponseReceived += new EventHandler<RemoteDataEventArgs<RemoteHostResponse>>(this.HandleHostResponseReceived);
     this.dsHandler.OnSessionConnected += new EventHandler(this.HandleSessionConnected);
     if (rsToUse == null)
     {
         throw PSTraceSource.NewInvalidOperationException("RemotingErrorIdStrings", "NestedPipelineMissingRunspace", new object[0]);
     }
     this.localPowerShell.Runspace = rsToUse;
     eventSubscriber.SubscribeEvents(this);
     this.stateOfSteppablePipeline = PSInvocationState.NotStarted;
 }
开发者ID:nickchal,项目名称:pash,代码行数:29,代码来源:ServerSteppablePipelineDriver.cs


示例9: RunInApartment

			/// <summary>
			/// Runs in the specified apartment
			/// </summary>
			private void RunInApartment(ThreadStart userDelegate, ApartmentState apartmentState)
			{
				Exception thrownException = null;

				Thread thread = new Thread(
				  delegate()
				  {
					  try
					  {
						  userDelegate.Invoke();
					  }
					  catch (Exception e)
					  {
						  thrownException = e;
					  }
				  });
				thread.SetApartmentState(apartmentState);

				thread.Start();
				thread.Join();

				if (thrownException != null)
				{
					ThrowExceptionPreservingStack(thrownException);
				}
			}
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:29,代码来源:ThreadRunner.cs


示例10: Run

        private void Run(ThreadStart userDelegate, ApartmentState apartmentState)
        {
            lastException = null;

            Thread thread = new Thread(
                delegate()
                    {
#if !DEBUG
                        try
                        {
#endif
                        userDelegate.Invoke();
#if !DEBUG
                        }
                        catch (Exception e)
                        {
                            lastException = e;
                        }
#endif
                    });
            thread.SetApartmentState(apartmentState);

            thread.Start();
            thread.Join();

            if (ExceptionWasThrown())
                ThrowExceptionPreservingStack(lastException);
        }
开发者ID:sivarajankumar,项目名称:dentalsmile,代码行数:28,代码来源:CrossThreadTestRunner.cs


示例11: Execute

		/// <summary>Invokes the specified delegate with the specified parameters in the specified kind of apartment state.</summary>
		/// <param name="d">The delegate to be invoked.</param>
		/// <param name="parameters">The parameters to pass to the delegate being invoked.</param>
		/// <param name="state">The apartment state to run under.</param>
		/// <returns>The result of calling the delegate.</returns>
		public static object Execute(
			Delegate d, object[] parameters, ApartmentState state)
		{
			if (d == null) throw new ArgumentNullException("d");
			if (state != ApartmentState.MTA && state != ApartmentState.STA)
				throw new ArgumentOutOfRangeException("state");

			if (Thread.CurrentThread.ApartmentState == state)
			{
				return d.DynamicInvoke(parameters);
			}
			else
			{
				ApartmentStateSwitcher switcher = new ApartmentStateSwitcher();
				switcher._delegate = d;
				switcher._parameters = parameters;

				Thread t = new Thread(new ThreadStart(switcher.Run));
				t.ApartmentState = state;
				t.IsBackground = true;
				t.Start();
				t.Join();

				if (switcher._exc != null) throw switcher._exc;
				return switcher._rv;
			}
		}
开发者ID:babgvant,项目名称:EVRPlay,代码行数:32,代码来源:ApartmentStateSwitcher.cs


示例12: RunInApartmentFromApartment

		/// <summary>
		/// A common helper method that tests running a test in an apartment from an apartment.
		/// </summary>
		private bool RunInApartmentFromApartment(ApartmentState fromApartMent, ApartmentState inApartment)
		{
			bool wasRunInCorrectApartment = false;

			Thread runnerThread = new Thread((ThreadStart)delegate
			{
				if (inApartment == ApartmentState.MTA)
				{
					ThreadRunner.RunInMTA(delegate
					{
						wasRunInCorrectApartment = Thread.CurrentThread.GetApartmentState() == inApartment;
					});
				}
				else if (inApartment == ApartmentState.STA)
				{
					ThreadRunner.RunInSTA(delegate
					{
						wasRunInCorrectApartment = Thread.CurrentThread.GetApartmentState() == inApartment;
					});
				}
			}
			);
			runnerThread.SetApartmentState(fromApartMent);
			runnerThread.Start();
			runnerThread.Join();

			return wasRunInCorrectApartment;
		}
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:31,代码来源:ThreadRunnerTests.cs


示例13: NUnitConfiguration

        /// <summary>
        /// Class constructor initializes fields from config file
        /// </summary>
        static NUnitConfiguration()
        {
            try
            {
                NameValueCollection settings = GetConfigSection("NUnit/TestCaseBuilder");
                if (settings != null)
                {
                    string oldStyle = settings["OldStyleTestCases"];
                    if (oldStyle != null)
                            allowOldStyleTests = Boolean.Parse(oldStyle);
                }

                settings = GetConfigSection("NUnit/TestRunner");
                if (settings != null)
                {
                    string apartment = settings["ApartmentState"];
                    if (apartment != null)
                        apartmentState = (ApartmentState)
                            System.Enum.Parse(typeof(ApartmentState), apartment, true);

                    string priority = settings["ThreadPriority"];
                    if (priority != null)
                        threadPriority = (ThreadPriority)
                            System.Enum.Parse(typeof(ThreadPriority), priority, true);
                }
            }
            catch (Exception ex)
            {
                string msg = string.Format("Invalid configuration setting in {0}",
                    AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
                throw new ApplicationException(msg, ex);
            }
        }
开发者ID:scottwis,项目名称:eddie,代码行数:36,代码来源:NUnitConfiguration.cs


示例14: DedicatedThreadPoolSettings

 public DedicatedThreadPoolSettings(int numThreads,
                                    string name = null,
                                    TimeSpan? deadlockTimeout = null,
                                    ApartmentState apartmentState = ApartmentState.Unknown,
                                    Action<Exception> exceptionHandler = null,
                                    int threadMaxStackSize = 0)
     : this(numThreads, DefaultThreadType, name, deadlockTimeout, apartmentState, exceptionHandler, threadMaxStackSize)
 { }
开发者ID:juergenhoetzel,项目名称:akka.net,代码行数:8,代码来源:Helios.Concurrency.DedicatedThreadPool.cs


示例15: InitializeThreadState

 private void InitializeThreadState(object threadParams, ThreadWorkerMethodWithReturn workerMethod, ApartmentState aptState, bool background)
 {
     this.threadParams = threadParams;
     this.threadWorkerMethodWithReturn = workerMethod;
     this.thread = new Thread(new ThreadStart(this.ThreadEntryPointMethodWithReturn));
     this.thread.SetApartmentState(aptState);
     this.backgroundThread = background;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:ThreadDispatch.cs


示例16: ServerPowerShellDriver

        private IRSPDriverInvoke _psDriverInvoker;  // Handles nested invocation of PS drivers.

        #endregion Private Members

        #region Constructors

#if !CORECLR
        /// <summary>
        /// Default constructor for creating ServerPowerShellDrivers
        /// </summary>
        /// <param name="powershell">decoded powershell object</param>
        /// <param name="extraPowerShell">extra pipeline to be run after <paramref name="powershell"/> completes</param>
        /// <param name="noInput">whether there is input for this powershell</param>
        /// <param name="clientPowerShellId">the client powershell id</param>
        /// <param name="clientRunspacePoolId">the client runspacepool id</param>
        /// <param name="runspacePoolDriver">runspace pool driver 
        /// which is creating this powershell driver</param>
        /// <param name="apartmentState">apartment state for this powershell</param>
        /// <param name="hostInfo">host info using which the host for
        /// this powershell will be constructed</param>
        /// <param name="streamOptions">serialization options for the streams in this powershell</param>
        /// <param name="addToHistory">
        /// true if the command is to be added to history list of the runspace. false, otherwise.
        /// </param>
        /// <param name="rsToUse">
        /// If not null, this Runspace will be used to invoke Powershell.
        /// If null, the RunspacePool pointed by <paramref name="runspacePoolDriver"/> will be used.
        /// </param>
        internal ServerPowerShellDriver(PowerShell powershell, PowerShell extraPowerShell, bool noInput, Guid clientPowerShellId,
            Guid clientRunspacePoolId, ServerRunspacePoolDriver runspacePoolDriver,
            ApartmentState apartmentState, HostInfo hostInfo, RemoteStreamOptions streamOptions,
            bool addToHistory, Runspace rsToUse)
            : this(powershell, extraPowerShell, noInput, clientPowerShellId, clientRunspacePoolId, runspacePoolDriver,
                   apartmentState, hostInfo, streamOptions, addToHistory, rsToUse, null)
        {
        }
开发者ID:40a,项目名称:PowerShell,代码行数:36,代码来源:ServerPowerShellDriver.cs


示例17: TestWorker

        /// <summary>
        /// Construct a new TestWorker.
        /// </summary>
        /// <param name="queue">The queue from which to pull work items</param>
        /// <param name="name">The name of this worker</param>
        /// <param name="apartmentState">The apartment state to use for running tests</param>
        public TestWorker(WorkItemQueue queue, string name, ApartmentState apartmentState)
        {
            _readyQueue = queue;

            _workerThread = new Thread(new ThreadStart(TestWorkerThreadProc));
            _workerThread.Name = name;
            _workerThread.SetApartmentState(apartmentState);
        }
开发者ID:balaghanta,项目名称:nunit-framework,代码行数:14,代码来源:TestWorker.cs


示例18: Start

 public void Start(ApartmentState state = ApartmentState.MTA)
 {
     if (thread == null)
     {
         thread = new Thread(WorkThread);
         thread.SetApartmentState(state);
         thread.Start();
     }
 }
开发者ID:yoykiee,项目名称:ShareX,代码行数:9,代码来源:ThreadWorker.cs


示例19: BackgroundWorker

 public BackgroundWorker(IPendingWorkCollection<IScheduledTask> pendingWorkCollection, ApartmentState apartmentState)
 {
     _cancellationTokenSource = new CancellationTokenSource();
     _pendingWorkCollection = pendingWorkCollection;
     _apartmentState = apartmentState;
     _isDisposing = false;
     _isDisposed = false;
     _isStarted = false;
 }
开发者ID:charlesw,项目名称:airion,代码行数:9,代码来源:BackgroundWorker.cs


示例20: ExecutionQueue

 public ExecutionQueue(ApartmentState state)
 {
     _executionThread = new Thread(ExecutionThread);
     _executionThread.IsBackground = true;
     _executionThread.Name = "ExecutionThread";
     _executionThread.SetApartmentState(state);
     _executionThread.Start();
     _commandDispatcher = (action) => action();
 }
开发者ID:TerabyteX,项目名称:main,代码行数:9,代码来源:ExecutionQueue.cs



注:本文中的ApartmentState类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Api类代码示例发布时间:2022-05-24
下一篇:
C# AosWeaponAttributes类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap