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();
                        }
                    }
                }
            });
        }
Example #2
0
        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();
            }
        }
Example #3
0
        /// <summary>
        /// 控制线程顺序
        /// //两个委托封装回调
        /// </summary>
        /// <param name="threadStart"></param>
        /// <param name="actionCallBack"></param>
        private void ThreadWithCallBack(ThreadStart threadStart, Action actionCallBack)
        {
            //1.While 死循环 判断状态 等待
            //2.Join
            //Thread thread = new Thread(threadStart);
            //thread.Start();
            ////{
            ////    while (thread.ThreadState != ThreadState.Stopped)
            ////    {
            ////        Thread.Sleep(100);
            ////    }
            ////    actionCallBack.Invoke();
            ////}
            //{
            //    thread.Join(); //卡界面
            //    actionCallBack.Invoke();
            //}
            ThreadStart method = () =>
            {
                threadStart.Invoke();
                actionCallBack.Invoke();
            };

            Thread thread = new Thread(method);

            thread.Start();
        }
Example #4
0
        /// <summary>
        /// starts thread with target if any
        /// </summary>
        private void StartTarget()
        {
            Exception exceptn       = null;
            var       bHadException = false;

            try
            {
                if (_ts != null)
                {
                    _ts.Invoke();
                }
                else if (_pts != null)
                {
                    _pts.Invoke(ThreadStartArg);
                }
            }
            catch (Exception ex)
            {
                bHadException      = true;
                exceptn            = ex;
                this.LastException = ex;
                OnThreadException(ex);
            }
            finally
            {
                OnThreadCompleted(bHadException, exceptn);
            }
        }
Example #5
0
        /// <summary>
        /// starts thread with target if any
        /// </summary>
        protected void startTarget()
        {
            Exception exceptn       = null;
            bool      bHadException = false;

            try
            {
                bThreadIsAborting = false;
                if (_Ts != null)
                {
                    _Ts.Invoke();
                }
                else if (_Pts != null)
                {
                    _Pts.Invoke(ThreadStartArg);
                }
            }
            catch (Exception ex)
            {
                bHadException = true;
                exceptn       = ex;
                //this._lastException = ex;
                this.LastException = ex;
                OnThreadException(ex);
            }
            finally
            {
                OnThreadCompleted(bHadException, exceptn);
            }
        }
Example #6
0
        private void onSearch(v_lhproducts_policyModel where)
        {
            var action = new Action(() =>
            {
                PageResult <v_lhproducts_policyModel> result = null;
                string countStr = $"第【{page}】页/共【{count}】页";

                try
                {
                    btnNext.Enabled = btnLast.Enabled = btn查询.Enabled = btn重置.Enabled = btnConfirm.Enabled = btnReturn.Enabled = false;
                    result          = _service.GetPolicyProducts(header, where, page, size);

                    total = result.Total;

                    count  = total / size;
                    count += total % size > 0 ? 1 : 0;

                    countStr = $"第【{page}】页/共【{count}】页";

                    labCount.Text          = countStr;
                    gridControl.DataSource = result.Result;

                    btnNext.Enabled   = btnLast.Enabled =
                        btn查询.Enabled = btn重置.Enabled = btnConfirm.Enabled = btnReturn.Enabled = true;
                }
                catch (Exception e)
                {
                    MsgHelper.ShowInformation(e.Message);
                }
            });

            var t1 = new ThreadStart(action);

            t1.Invoke();
        }
			/// <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);
				}
			}
Example #8
0
        /// <summary>
        /// starts thread with target if any
        /// </summary>
        protected void StartTarget()
        {
            Exception exceptn       = null;
            bool      bHadException = false;

            try
            {
                bThreadIsAborting = false;
                if (ThreadStart != null)
                {
                    ThreadStart.Invoke();
                }
                else if (ParamterizedStart != null)
                {
                    ParamterizedStart.Invoke(_arg);
                }
            }
            catch (Exception ex)
            {
                bHadException       = true;
                exceptn             = ex;
                this._lastException = ex;
                OnThreadException(ex);
            }
            finally
            {
                OnThreadCompleted(bHadException, exceptn);
            }
        }
Example #9
0
    public static void RequestPath(PathRequest pathRequest)
    {
        ThreadStart threadStart = delegate { instance.pathfinderLogic.GoToTile(pathRequest, instance.DoneProcessing); };

        threadStart.Invoke();
        //Debug.Log("i Queue request count: " +instance.pathResQueue.Count);
    }
Example #10
0
 public static void SafeInvoke(this ThreadStart method)
 {
     if (method != null)
     {
         method.Invoke();
     }
 }
Example #11
0
        /// <summary>
        /// Run an operation in a certain apartment state.
        /// </summary>
        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 (lastException != null)
            {
                ThrowExceptionPreservingStack(lastException);
            }
        }
Example #12
0
        /// <summary>
        /// Wrap the start method for the aggregated Thread.  This method uses the "thread catalog"
        /// to keep track of which threads are running.  It also insures that any Exception that
        /// occurs in the start method will be caught and reported.
        /// </summary>
        private void WrappedStart()
        {
            lock ( mRunning )
            {
                mRunning.Add(this);
            }

            try
            {
                mStart.Invoke();
                Finished();
            }
            catch (Exception ex)
            {
                string name    = string.IsNullOrEmpty(mThread.Name) ? "Unnamed" : mThread.Name;
                string message = string.Format("Error in thread {0}:{1}", name, ex.Message);
                // DON'T throw this!  Since this is the start method of a thread there isn't
                // anything to catch it...
                //throw new ApplicationException( message, ex );
                Debug.Print("{0}\n{1}\n", message, ex.StackTrace);
            }

            lock ( mRunning )
            {
                mRunning.Remove(this);
            }
        }
Example #13
0
        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);
            }
        }
Example #14
0
 public static void onSyncTick()
 {
     while (syncTasks.Count > 0)
     {
         ThreadStart ts = syncTasks.Dequeue();
         if (ts != null)
         {
             ts.Invoke();
         }
     }
     for (LinkedListNode <DelayedTask> node = delayedTasks.First; node != null && node != delayedTasks.Last; node = node.Next)
     {
         DelayedTask task = node.Value;
         task.currentDelayCount--;
         if (task.currentDelayCount <= 0)
         {
             if (task.isAsync)
             {
                 runTaskAsynchronously(task.threadStart);
             }
             else
             {
                 runTaskSynchronously(task.threadStart);
             }
             if (task.repeat)
             {
                 task.currentDelayCount = task.delay;
             }
             else
             {
                 delayedTasks.Remove(node);
             }
         }
     }
 }
Example #15
0
        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);
            }
        }
Example #16
0
 public void onPressed()
 {
     if (task != null)
     {
         task.Invoke();
     }
 }
        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);
        }
 /// <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();
 }
Example #19
0
    public static void RequestPath(Vector3 pathStart, Vector3 pathEnd, Action <Vector3[], bool> callback, Grid grid)
    {
        ThreadStart threadStart = delegate {
            instance.pathfinding.FindPath(pathStart, pathEnd, callback, grid, instance.ResultEnqueue);
        };

        threadStart.Invoke();
    }
        ///<summary>Main path request method for pathfinding.</summary>
        ///<param name="pathStart">Starting coords</param>
        ///<param name="pathEnd">Ending coords</param>
        ///<param name="callback">Callback delegate</param>
        ///<param name="pathType">Type of path</param>
        //<returns>Returns an integer based on the passed value.</returns>
        public void RequestPath(Vector3 pathStart, Vector3 pathEnd, Action <List <Node>, Vector3[], bool> callback, PathType pathType)
        {
            ThreadStart threadStart = delegate {
                FindPath(pathStart, pathEnd, callback, pathType);   //Method on other page
            };

            threadStart.Invoke();
        }
 private void Run()
 {
     try {
         start.Invoke();
     } catch (Exception e) {
         lastException = e;
     }
 }
Example #22
0
    public static void RequestPath(PathRequest request)
    {
        ThreadStart threadStart = delegate {
            instance.pathfinding.Astar(PathGrid.mstrGrid[(int)request.pathStart.x, (int)request.pathStart.y], PathGrid.mstrGrid[(int)request.pathEnd.x, (int)request.pathEnd.y]);
        };

        threadStart.Invoke();
    }
Example #23
0
    public static void RequestPath(PathRequest request)
    {
        ThreadStart threadStart = delegate {
            GameManager.Instance.GridObj.FindPath(request, instance.FinishedProcessingPath);
        };

        threadStart.Invoke();
    }
Example #24
0
    public static void RequestPath(PathRequest request, bool ignoreUnwalkable)
    {
        ThreadStart threadStart = delegate {
            instance.pathfinding.FindPath(request, instance.FinishProcessingPath, ignoreUnwalkable);
        };

        threadStart.Invoke();
    }
Example #25
0
    public static void RequestPath(PathRequest request)
    {
        ThreadStart threadStart = delegate {
            instance.pathfinding.FindPath(request, instance.FinishedProcessingPath);
        };

        threadStart.Invoke();
    }
Example #26
0
    public void RecalculateMap()
    {
        ThreadStart thread = delegate {
            Create2DMap();
        };

        thread.Invoke();
    }
Example #27
0
        public void RequestPathOld(PathRequest request)
        {
            ThreadStart threadStart = delegate {
                //FindPathOld(request);   //Method on other page
            };

            threadStart.Invoke();
        }
Example #28
0
    public static void requestPath(PathRequest request)
    {
        ThreadStart threadStart = delegate {
            manager.pathFinder.FindPath(request, manager.finishedPathFinding);
        };

        threadStart.Invoke();
    }
Example #29
0
 private void SafeExecution(ThreadStart threadStart)
 {
     try { threadStart.Invoke(); }
     catch (Exception ex)
     {
         Exceptions.Write(ex);
     }
 }
Example #30
0
        /// <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)
        {
            _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(() =>
                {
                    try
                    {
                        waitDelegate.Invoke();
                    }
                    catch (Exception ex)
                    {
                        Log.Error().WriteLine(ex, "invoke error:");
                        threadException = ex;
                    }
                }
                                      )
                {
                    Name         = title,
                    IsBackground = true
                };
                _waitFor.SetApartmentState(ApartmentState.STA);
                _waitFor.Start();

                // Wait until finished
                while (!_waitFor.Join(TimeSpan.FromMilliseconds(100)))
                {
                    Application.DoEvents();
                }
                Log.Debug().WriteLine("Finished {0}", title);
            }
            catch (Exception ex)
            {
                Log.Error().WriteLine(ex);
                throw;
            }
            finally
            {
                Close();
            }
            // Check if an exception occured, if so throw it
            if (threadException != null)
            {
                throw threadException;
            }
        }
Example #31
0
    //Starts the threading process (Lague, 2017)
    public static void RequestPath(PathRequest pathRequest)
    {
        ThreadStart threadStart = delegate
        {
            PThreader.pathfinding.DrawPath(pathRequest, PThreader.Finished);
        };

        threadStart.Invoke();
    }
Example #32
0
        /// <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     = "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;
            }
        }
Example #33
0
        /// <summary>
        /// 实现细节,这里使用 BackgroundWorker 来实现后台线程,
        /// 注册 DoWork 和 Completed 事件,当执行一个任务前,将任务加入到工作任务集合(表示工作线程少了一个空闲),
        /// 一旦 RunWorkerCompleted 事件被出发则将任务从工作任务集合中移除(表示工作线程也空闲了一个)
        /// </summary>
        /// <param name="threadStart"></param>
        private static void ExecuteTaskByThread(ThreadStart threadStart)
        {
            threadsWorker.Add(threadStart);
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork             += (o, e) => { threadStart.Invoke(); };
            worker.RunWorkerCompleted += (o, e) => { threadsWorker.Remove(threadStart); };
            worker.RunWorkerAsync();
        }
    public static void RequestTrackingTarget(TargetTrackRequest _request)
    {
        ThreadStart threadStart = delegate
        {
            GetTracking().FindTarget(_request, instance.FinishedProcessing);
        };

        threadStart.Invoke();
    }
			/// <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();
				}
			}
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			this.Title = "Background Execution";
			
			this.btnStartLongRunningTask.TouchUpInside += (s, e) => {
				ThreadStart ts = new ThreadStart ( () => { this.DoSomething(); });
				ts.Invoke();
			};
		}
 void MultiThreadedWorker(ThreadStart userDelegate)
 {
     try
     {
         userDelegate.Invoke();
     }
     catch (Exception e)
     {
         lastException = e;
     }
 }
Example #38
0
		/// <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;
			}
		}
Example #39
0
 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();
 }
        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;
        }
Example #41
0
        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();
                               }
                           }
                       };
        }
        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();
            }
        }
Example #43
0
 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);
                    }
                };
 }
Example #44
0
 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();
                    }
                };
 }
Example #45
0
        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
        }
Example #46
0
 /// <summary>
 /// Executes task instance.
 /// </summary>
 /// <param name="task"></param>
 public void Execute(ThreadStart task)
 {
     count++;
     task.Invoke();
 }
Example #47
0
        public void InvokeReal(SimActor TheBot)
        {
   
            String use = TypeUsage.UsageName;

            // Create the Side-Effect closure
            ThreadStart closure = new ThreadStart(delegate()
                                                      {
                                                          InvokeBotSideEffect(TheBot);
                                                      });

            SimAssetStore simAssetSystem = SimAssetStore.TheStore;
            bool animFound = TypeUsage.UseSit;
            // IF UseAnim was specified
            if (!String.IsNullOrEmpty(TypeUsage.UseAnim))
            {
                UUID animID = simAssetSystem.GetAssetUUID(TypeUsage.UseAnim, AssetType.Animation);
                if (animID != UUID.Zero)
                {
                    closure = TheBot.WithAnim(animID, closure);
                    animFound = true;
                }
            }
            // else
            if (!animFound)
            {
                //ELSE look for Verb coverage for an anim
                UUID animID = simAssetSystem.GetAssetUUID(use, AssetType.Animation);
                if (animID != UUID.Zero)
                    closure = TheBot.WithAnim(animID, closure);
            }

            // Surround with tough/grab if needed
            if (use == "touch" || use == "grab" || TypeUsage.UseGrab)
                closure = TheBot.WithGrabAt(Target, closure);

            // Surround with Sit if needed
            if (use == "sit" || TypeUsage.UseSit)
                closure = TheBot.WithSitOn(Target, closure);


            // Approach Target
            try
            {
                double maximumDistance = TypeUsage.maximumDistance + Target.GetSizeDistance();
                double howClose = TheBot.Approach(Target, maximumDistance - 0.5);
                ((SimAvatarImpl)TheBot).ApproachVector3D = Target.GlobalPosition;
                TheBot.TurnToward(Target);
                if (howClose > maximumDistance + 1)
                {
                    Debug(TheBot, "Too far away " + howClose + " from " + this);
                    return;
                }
                Target.PathFinding.MakeEnterable(TheBot);
                closure.Invoke();
                //if (Target == TheBot.ApproachPosition)
               // {
                 //   ((SimAvatarImpl) TheBot).ApproachPosition = null;
                 //   TheBot.StopMoving();
                //}
            }
            finally
            {
                Target.PathFinding.RestoreEnterable(TheBot);
            }
        }