当前位置: 首页>>代码示例>>C#>>正文


C# ThreadStart.Invoke方法代码示例

本文整理汇总了C#中ThreadStart.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# ThreadStart.Invoke方法的具体用法?C# ThreadStart.Invoke怎么用?C# ThreadStart.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ThreadStart的用法示例。


在下文中一共展示了ThreadStart.Invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunInSTA

 /// <summary>
 /// Runs a specific method in Single Threaded apartment
 /// </summary>
 /// <param name="userDelegate">A delegate to run</param>
 public void RunInSTA(ThreadStart userDelegate)
 {
     if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
         Run(userDelegate, ApartmentState.STA);
     else
         userDelegate.Invoke();
 }
开发者ID:madcapsoftware,项目名称:AvalonUnitTesting,代码行数:11,代码来源:STAOperationRunner.cs

示例2: 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

示例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: 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

示例5: Run

			/// <summary>
			/// Runs a specific method in Single Threaded apartment
			/// </summary>
			/// <param name="userDelegate">A delegate to run</param>
			public void Run(ThreadStart userDelegate, ApartmentState apartment)
			{
				if (Thread.CurrentThread.GetApartmentState() != apartment)
				{
					RunInApartment(userDelegate, apartment);
				}
				else
				{
					userDelegate.Invoke();
				}
			}
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:15,代码来源:ThreadRunner.cs

示例6: MultiThreadedWorker

 void MultiThreadedWorker(ThreadStart userDelegate)
 {
     try
     {
         userDelegate.Invoke();
     }
     catch (Exception e)
     {
         lastException = e;
     }
 }
开发者ID:MartinDemberger,项目名称:Costura,代码行数:11,代码来源:CrossThreadRunner.cs

示例7: ViewDidLoad

		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			this.Title = "Background Execution";
			
			this.btnStartLongRunningTask.TouchUpInside += (s, e) => {
				ThreadStart ts = new ThreadStart ( () => { this.DoSomething(); });
				ts.Invoke();
			};
		}
开发者ID:GSerjo,项目名称:monotouch-samples,代码行数:11,代码来源:HomeScreen_iPhone.xib.cs

示例8: ShowAndWait

		/// <summary>
		/// Show the "please wait" form, execute the code from the delegate and wait until execution finishes.
		/// The supplied delegate will be wrapped with a try/catch so this method can return any exception that was thrown.
		/// </summary>
		/// <param name="title">The title of the form (and Thread)</param>
		/// <param name="text">The text in the form</param>
		/// <param name="waitDelegate">delegate { with your code }</param>
		public void ShowAndWait(string title, string text, ThreadStart waitDelegate) {
			this.title = title;
			Text = title;
			label_pleasewait.Text = text;
			cancelButton.Text = Language.GetString("CANCEL");

			// Make sure the form is shown.
			Show();
			
			// Variable to store the exception, if one is generated, from inside the thread.
			Exception threadException = null;
			try {
				// Wrap the passed delegate in a try/catch which makes it possible to save the exception
				waitFor = new Thread(new ThreadStart(
					delegate {
						try {
							waitDelegate.Invoke();
						} catch (Exception ex) {
							LOG.Error("invoke error:", ex);
							threadException = ex;
						}
					})
				);
				waitFor.Name = title;
				waitFor.IsBackground = true;
				waitFor.SetApartmentState(ApartmentState.STA);
				waitFor.Start();
	
				// Wait until finished
				while (!waitFor.Join(TimeSpan.FromMilliseconds(100))) {
					Application.DoEvents();
				}
				LOG.DebugFormat("Finished {0}", title);
			} catch (Exception ex) {
				LOG.Error(ex);
				throw;
			} finally {
				Close();
			}
			// Check if an exception occured, if so throw it
			if (threadException != null) {
				throw threadException;
			}
		}
开发者ID:logtcn,项目名称:greenshot,代码行数:51,代码来源:PleaseWaitForm.cs

示例9: RunCodeAsSTA

 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();
 }
开发者ID:Robin--,项目名称:Warewolf,代码行数:19,代码来源:ThreadExecuter.cs

示例10: RunTask

        public static Thread RunTask(ThreadStart task)
        {
            if (_semaphore == null)
            {
                if (MaxThreads == 0)
                    MaxThreads = 10;

                _semaphore = new Semaphore(MaxThreads, MaxThreads);
            }

            _semaphore.WaitOne();

            var t = new Thread(delegate()
            {
                try
                {
                    task.Invoke();
                }
                finally
                {
                    _semaphore.Release();

                    //Remove thread from _thread list
                    lock (_threads)
                    {
                        if (_threads.Contains(Thread.CurrentThread))
                            _threads.Remove(Thread.CurrentThread);
                    }
                }
            });
            t.IsBackground = true;

            lock (_threads)
                _threads.Add(t);

            t.Start();

            return t;
        }
开发者ID:LordBlacksun,项目名称:Allegiance-Community-Security-System,代码行数:39,代码来源:TaskHandler.cs

示例11: scanDirectory

        protected static void scanDirectory(string path, bool newThread = true)
        {
            logger.Info("Scanning directory {0}", path);

            var t = new ThreadStart(delegate
                {
                    var hashingService = HashingService.GetHashingService();

                    if (!Directory.Exists(path))
                        return;

                    foreach (var file in Directory.GetFiles(path))
                    {
                        hashingService.GetHashAsync(file, Priority.Low);
                    }

                    foreach (var dir in Directory.GetDirectories(path))
                    {
                        scanDirectory(dir, false);
                    }
                });

            if (newThread)
            {
                new Thread(t).Start();
            }
            else
            {
                t.Invoke();
            }
        }
开发者ID:ap0llo,项目名称:wolpertinger,代码行数:31,代码来源:FileShareServerComponent.cs

示例12: WithGrabAt

 public ThreadStart WithGrabAt(SimObject obj, ThreadStart closure)
 {
     var Client = GetGridClient();
     return () =>
                {
                    Primitive targetPrim = obj.Prim;
                    uint objectLocalID = targetPrim.LocalID;
                    AgentManager ClientSelf = Client.Self;
                    try
                    {
                        ClientSelf.Grab(objectLocalID);
                        closure.Invoke();
                    }
                    finally
                    {
                        ClientSelf.DeGrab(objectLocalID);
                    }
                };
 }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:19,代码来源:SimAvatarClient.cs

示例13: WithAnim

 public ThreadStart WithAnim(SimAsset anim, ThreadStart closure)
 {
     var Client = GetGridClient();
     AssetThread assetThread = new AssetThread(Client.Self, anim);
     return () =>
                {
                    try
                    {
                        assetThread.Start();
                        closure.Invoke();
                    }
                    finally
                    {
                        assetThread.Stop();
                    }
                };
 }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:17,代码来源:SimAvatarClient.cs

示例14: ExecuteCmdletBase

        public void ExecuteCmdletBase(PSCmdlet callingCmdlet)
        {
            CallingCmdlet = callingCmdlet;
            Completed = new ManualResetEvent(false);
            ProgressEvent = new AutoResetEvent(false);
            LogMessageEvent = new AutoResetEvent(false);

            Events = new WaitHandle[] { Completed, ProgressEvent, LogMessageEvent };

            //The init of the MapManager and the setting up of the binding takes time,
            //starting it async gives instant progress feedback to the user in the cmdlet.
            ThreadStart initMapManagerThread = new ThreadStart(InitMapManager);
            initMapManagerThread.Invoke();

            int index = -1;
            do
            {
                index = WaitHandle.WaitAny(Events);

                if (index == 1)
                {
                    lock (pr_lock)
                    {
                        WriteProgress(ProgressRecord);
                    }
                }
                else if (index == 2)
                {
                    lock(msg_lock) 
                    {
                        WriteWarningMessage(Message);
                    }
                }
            }
            while (index != 0); //0 is the Completed event
        }
开发者ID:chris-tomich,项目名称:Glyma,代码行数:36,代码来源:Export_SPGLMapBase.cs

示例15: WithSitOn

        public ThreadStart WithSitOn(SimObject obj, ThreadStart closure)
        {
            bool CanUseSit = WorldSystem.CanUseSit;
            return () =>
                       {
                           bool SattedUpon = false;
                           if (CanUseSit)
                           {
                               SattedUpon = SitOn(obj);
                           }

                           try
                           {
                               closure.Invoke();
                           }
                           finally
                           {
                               if (CanUseSit)
                               {
                                   if (SattedUpon) StandUp();
                               }
                           }
                       };
        }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:24,代码来源:SimAvatarClient.cs


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