Esempio n. 1
0
 public static void ExecuteInMultiThreads(ThreadMethod method1, ThreadMethod method2, Int32 threadsCount)
 {
     ExecuteInMultiThreads(new List <ThreadMethod>()
     {
         method1, method2
     }, threadsCount);
 }
Esempio n. 2
0
 public void StartProcessThreads(ThreadMethod processMethod)
 {
     for (int i = 0; i < _processThreads.Length; i++)
     {
         _processThreads[i] = new Thread(new ThreadStart(processMethod));
         _processThreads[i].Start();
     }
 }
Esempio n. 3
0
        public Client(Settings settings, User user, AuthorizationData authData, ThreadMethod listening, bool firstRun)
        {
            this.Settings = settings;
            this.User     = user;
            this.AuthData = authData;
            if (firstRun)
            {
                RdpSession = new RDPSession();
            }
            ThreadStart threadDelegate = new ThreadStart(listening);

            MessageListener = new Thread(threadDelegate);
        }
Esempio n. 4
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            MaterialOutBusiness material = new MaterialOutBusiness();
            DataTable           table    = material.GetOutStoreMessage();

            method = new ThreadMethod(LoadFile);
            Thread thread = new Thread(() =>
            {
                GetInfo(table);
            });

            thread.IsBackground = true;
            thread.Start();
        }
Esempio n. 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="method"></param>
        /// <param name="parameters"></param>
        public static void AddToPool
        (
            ThreadMethod method,
            params object[] parameters)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }
            ThreadRunner runner = new ThreadRunner();

            runner._method     = method;
            runner._parameters = parameters;
            ThreadPool.QueueUserWorkItem(runner._MethodCallback);
        }
Esempio n. 6
0
        public Thread CreateThread(ThreadMethod target)
        {
            if (this.ThreadCount < this.PoolSize)
            {
                Thread clientThread = new Thread(new ParameterizedThreadStart(target));
                string threadname = string.Format("{0}{1}", THREADNAME, ThreadCount++);
                clientThread.IsBackground = true;

                if (!Threads.ContainsKey(threadname))
                    Threads[threadname] = clientThread;
                else Threads.Add(threadname, clientThread);

                return clientThread;
            }
            else throw new ThreadOverflowException("Error: Attempting to add more client threads than possible");
        }
Esempio n. 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="method"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static Thread RunThread
        (
            ThreadMethod method,
            params object[] parameters)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }
            ThreadRunner runner = new ThreadRunner();

            runner._method     = method;
            runner._parameters = parameters;
            ThreadStart start  = new ThreadStart(runner._RunMethod);
            Thread      result = new Thread(start);

            result.IsBackground = true;
            result.Start();
            return(result);
        }
Esempio n. 8
0
        public NiThread(ThreadMethod threadMethodStart,
                        ThreadMethod threadMethodStop,
                        string threadName,
                        int threadTimeoutInMs)
        {
            this.threadTimeoutInMs = threadTimeoutInMs;
            threadStart            = new SemaphoreSlim(0, 1);
            threadEnd     = new SemaphoreSlim(0, 1);
            threadTrigger = new SemaphoreSlim(0, 1);

            theRuntimeDelegate  = threadMethodStart;
            theStoppingDelegate = threadMethodStop;
            ThreadStart delegateHelp = StartThreadExecute;

            if (delegateHelp != null)
            {
                theThread = new Thread(delegateHelp)
                {
                    IsBackground = true
                };
            }
        }
        /// <summary>
        /// LateUpdate will prepare and call for calculations on each particle system.
        /// All threaded calculation is done after Update to ensure stable movement of particles.
        /// </summary>
        void LateUpdate()
        {
            activeThreads = 0;
            if (activeSystems.Count>0)
                activeSystems.Clear();
            frameCount++;
            isFirstUnsafeAutomaticFrames = frameCount<unsafeAutomaticThreadFrames||threadAggregatorRuns<unsafeAutomaticThreadFrames;
            if (reference!=this) {
                InitializePlayground();
                return;
            }

            // Update time
            SetTime();

            // Check the global event delegates for availability
            CheckEvents();

            // Prepare all global manipulators
            for (int m = 0; m<manipulators.Count; m++)
                manipulators[m].Update();

            // Return if no particle systems are available
            if (particleSystems.Count==0)
                return;

            hasActiveParticleSystems = false;
            hasLocalNoThreads = false;
            hasLocalOnePerSystem = false;
            hasLocalOneForAll = false;
            hasActiveSkinnedMeshes = false;
            hasActiveTurbulence = false;
            if (previousThreadMethod!=threadMethod) {
                isDoneThread = true;
                previousThreadMethod = threadMethod;
            }
            if (threadMethod!=ThreadMethod.OneForAll)
                isDoneThread = true;
            if (previousSkinnedMeshThreadMethod!=skinnedMeshThreadMethod) {
                isDoneThreadSkinned = true;
                previousSkinnedMeshThreadMethod = skinnedMeshThreadMethod;
            }
            if (previousTurbulenceThreadMethod!=turbulenceThreadMethod) {
                isDoneThreadTurbulence = true;
                previousTurbulenceThreadMethod = turbulenceThreadMethod;
            }

            // Prepare all particle systems
            Camera mainCamera = Camera.main;
            bool frustumPlanesSet = false;
            bool hasSourceUpdateNow = false;
            int currentParticleSystemCount = particleSystems.Count;
            for (int i = 0; i<particleSystems.Count; i++) {
                if (particleSystems[i]!=null &&
                    !particleSystems[i].isSnapshot &&
                    particleSystems[i].shurikenParticleSystem!=null &&
                    particleSystems[i].particleSystemGameObject.activeInHierarchy &&
                    particleSystems[i].Initialized() &&
                    !particleSystems[i].IsSettingParticleCount() &&
                    !particleSystems[i].IsSettingLifetime() &&
                    !particleSystems[i].IsYieldRefreshing() &&
                    !particleSystems[i].InTransition() &&
                    !particleSystems[i].IsLoading() &&
                    !particleSystems[i].IsPrewarming() &&
                    !particleSystems[i].IsSettingParticleTime()) {

                    // Catch up Shuriken particle lifetime with the update rate
                    if (Time.frameCount%particleSystems[i].updateRate!=0) {
                        for (int p = 0; p<particleSystems[i].particleCount; p++)
                            particleSystems[i].particleCache[p].lifetime = (particleSystems[i].playgroundCache.death[p]-particleSystems[i].playgroundCache.birth[p])-particleSystems[i].playgroundCache.lifetimeSubtraction[p];
                        particleSystems[i].isReadyForThreadedCalculations = false;
                        continue;
                    }

                    // Handle any system additions or removals
                    if (currentParticleSystemCount > particleSystems.Count) {
                        if (i>0) {
                            i--;
                            currentParticleSystemCount = particleSystems.Count;
                        } else {hasActiveParticleSystems=false; return;}
                    } else if (currentParticleSystemCount < particleSystems.Count) {
                        currentParticleSystemCount = particleSystems.Count;
                    }
                    if (particleSystems.Count==0 || i>=particleSystems.Count) {hasActiveParticleSystems=false; return;}

                    // Update the main camera frustum planes (this is used for culling particle systems)
                    if (!frustumPlanesSet && particleSystems[i].pauseCalculationWhenInvisible && mainCamera!=null && mainCamera.enabled) {
                        frustumPlanes = GeometryUtility.CalculateFrustumPlanes(mainCamera);
                        frustumPlanesSet = true;
                    }

                    // Update any particle system using onlySourcePositioning or onlyLifetimePositioning
                    if (particleSystems[i].onlySourcePositioning||particleSystems[i].onlyLifetimePositioning)
                        if (!particleSystems[i].UpdateSystem())
                            continue;

                    // Update any changes. Particle system may also be removed here.
                    if (particleSystems.Count>0 && i<particleSystems.Count) {

                        // Prepare for threaded calculations
                        particleSystems[i].isReadyForThreadedCalculations = particleSystems[i].PrepareThreadedCalculations();
                        if (particleSystems[i].IsAlive()) {
                            hasActiveParticleSystems = true;
                            if (particleSystems[i].onlySourcePositioning||particleSystems[i].onlyLifetimePositioning)
                                hasSourceUpdateNow = true;
                            if (threadMethod==ThreadMethod.Automatic)
                                activeSystems.Add (i);
                            if (!particleSystems[i].forceSkinnedMeshUpdateOnMainThread && particleSystems[i].IsSkinnedWorldObjectReady() && particleSystems[i].calculate)
                                hasActiveSkinnedMeshes = true;
                            if (particleSystems[i].HasTurbulence() && particleSystems[i].calculate)
                                hasActiveTurbulence = true;

                            switch (particleSystems[i].threadMethod) {
                                case ThreadMethodLocal.NoThreads:hasLocalNoThreads=true;break;
                                case ThreadMethodLocal.OnePerSystem:hasLocalOnePerSystem=true;break;
                                case ThreadMethodLocal.OneForAll:hasLocalOneForAll=true;break;
                            }
                        } else particleSystems[i].isReadyForThreadedCalculations = false;
                    } else if (particleSystems.Count>0 && i<particleSystems.Count && particleSystems[i]!=null) {
                        particleSystems[i].isReadyForThreadedCalculations = false;
                    }
                } else if (particleSystems[i]!=null) {
                    particleSystems[i].isReadyForThreadedCalculations = false;
                    if (particleSystems[i].IsPrewarming()) {
                        if (particleSystems[i].HasTurbulence()) {
                            hasActiveTurbulence = true;
                            hasActiveParticleSystems = true;
                        }
                    }
                }

            }

            // Proceed if we have any active particle systems
            if (hasActiveParticleSystems) {

                // Call for threaded calculations
                ThreadAggregator();

                // Call for immediate update on particle systems using onlySourcePositioning or onlyLifetimePositioning
                if (hasSourceUpdateNow) {
                    for (int i = 0; i<particleSystems.Count; i++) {
                        if (particleSystems[i]!=null &&
                            (particleSystems[i].onlySourcePositioning || particleSystems[i].onlyLifetimePositioning) &&
                            particleSystems[i].isReadyForThreadedCalculations &&
                            !particleSystems[i].InTransition() &&
                            !particleSystems[i].IsLoading() &&
                            particleSystems[i].IsReady()) {
                            particleSystems[i].UpdateShuriken();
                        }
                    }
                }
            }

            // Reset hierarchy repaint check
            #if UNITY_EDITOR
            PlaygroundParticlesC.didHierarchyRepaint = false;
            #endif
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="ToFactor">The value to factor.</param>
 public PollableThreadManager(int ID, ThreadMethod DoExecution)
 {
     m_startTime   = DateTime.Now;
     m_id          = ID;
     m_doExecution = DoExecution;
 }
Esempio n. 11
0
 public MethodThreadWrapper(ThreadMethod <ReturnType> method)
     : base()
 {
     _method = method; _finished = false;
 }
Esempio n. 12
0
 public void StartWriteThread(ThreadMethod writingMethod)
 {
     _writeThread = new Thread(new ThreadStart(writingMethod));
     _writeThread.Start();
 }
Esempio n. 13
0
 public void StartReadThread(ThreadMethod readingMethod)
 {
     _readThread = new Thread(new ThreadStart(readingMethod));
     _readThread.Start();
 }
Esempio n. 14
0
 public ThreadHandler(ThreadMethod method, int sleepMilliseconds, bool exitOnException)
 {
     Method            = method;
     SleepMilliseconds = sleepMilliseconds;
     ExitOnException   = exitOnException;
 }
Esempio n. 15
0
 public static extern IntPtr CreateThread(IntPtr securityAttributes, uint stackSize,
                                          ThreadMethod startFunction, IntPtr threadParameter, uint creationFlags, out uint threadId);
Esempio n. 16
0
        // Update is called both in Edit- and Play Mode once per frame
        void Update()
        {
            activeThreads = 0;
            frameCount++;
            isFirstUnsafeAutomaticFrames = frameCount<unsafeAutomaticThreadFrames||threadAggregatorRuns<unsafeAutomaticThreadFrames;
            if (reference!=this) {
                InitializePlayground();
                return;
            }

            // Update time
            SetTime();

            // Check the global event delegates for availability
            CheckEvents();

            // Prepare all global manipulators
            for (int m = 0; m<manipulators.Count; m++)
                manipulators[m].Update();

            // Return if no particle systems are available
            if (particleSystems.Count==0)
                return;

            hasActiveParticleSystems = false;
            hasLocalNoThreads = false;
            hasLocalOnePerSystem = false;
            hasLocalOneForAll = false;
            hasActiveSkinnedMeshes = false;
            hasActiveTurbulence = false;
            if (previousThreadMethod!=threadMethod) {
                isDoneThread = true;
                previousThreadMethod = threadMethod;
            }
            if (threadMethod!=ThreadMethod.OneForAll)
                isDoneThread = true;
            if (previousSkinnedMeshThreadMethod!=skinnedMeshThreadMethod) {
                isDoneThreadSkinned = true;
                previousSkinnedMeshThreadMethod = skinnedMeshThreadMethod;
            }
            if (previousTurbulenceThreadMethod!=turbulenceThreadMethod) {
                isDoneThreadTurbulence = true;
                previousTurbulenceThreadMethod = turbulenceThreadMethod;
            }

            // Prepare all particle systems
            int currentParticleSystemCount = particleSystems.Count;
            for (int i = 0; i<particleSystems.Count; i++) {
                if (particleSystems[i]!=null &&
                    particleSystems[i].calculate &&
                    !particleSystems[i].isSnapshot &&
                    particleSystems[i].shurikenParticleSystem!=null &&
                    particleSystems[i].particleSystemGameObject.activeInHierarchy &&
                    particleSystems[i].Initialized() &&
                    !particleSystems[i].IsSettingParticleCount() &&
                    !particleSystems[i].IsSettingLifetime() &&
                    !particleSystems[i].IsYieldRefreshing() &&
                    !particleSystems[i].InTransition() &&
                    !particleSystems[i].IsLoading() &&
                    Time.frameCount%particleSystems[i].updateRate==0) {

                    if (currentParticleSystemCount > particleSystems.Count) {
                        if (i>0) {
                            i--;
                            currentParticleSystemCount = particleSystems.Count;
                        } else return;
                    } else if (currentParticleSystemCount < particleSystems.Count) {
                        currentParticleSystemCount = particleSystems.Count;
                    }

                    if (particleSystems.Count==0 || i>=particleSystems.Count) return;

                    // Update any changes. Particle system may also be removed here.
                    if (particleSystems[i].UpdateSystem() && (particleSystems.Count>0 && i<particleSystems.Count)) {

                        // Prepare for threaded calculations
                        particleSystems[i].isReadyForThreadedCalculations = particleSystems[i].PrepareThreadedCalculations();
                        if (particleSystems[i].IsAlive()) {
                            hasActiveParticleSystems = true;
                            if (particleSystems[i].IsSkinnedWorldObjectReady())
                                hasActiveSkinnedMeshes = true;
                            if (particleSystems[i].HasTurbulence())
                                hasActiveTurbulence = true;

                            switch (particleSystems[i].threadMethod) {
                                case ThreadMethodLocal.NoThreads:hasLocalNoThreads=true;break;
                                case ThreadMethodLocal.OnePerSystem:hasLocalOnePerSystem=true;break;
                                case ThreadMethodLocal.OneForAll:hasLocalOneForAll=true;break;
                            }
                        } else particleSystems[i].isReadyForThreadedCalculations = false;
                    } else if (particleSystems.Count>0 && i<particleSystems.Count && particleSystems[i]!=null) {
                        particleSystems[i].isReadyForThreadedCalculations = false;
                    }
                } else if (particleSystems[i]!=null)
                    particleSystems[i].isReadyForThreadedCalculations = false;

            }

            // Call for threaded calculations
            if (hasActiveParticleSystems)
                ThreadAggregator();
        }
Esempio n. 17
0
 /// <summary>
 /// Subscribes to an event asynchronously.
 /// </summary>
 /// <param name="action">Callback function called when the event is raised.</param>
 /// <param name="threadOption">Thread option.</param>
 /// <param name="keepSubscriberReferenceAlive">If set to <c>true</c> keep subscriber reference alive.</param>
 /// <param name="filter">Filter.</param>
 /// <typeparam name="TEvent">The type of the event.</typeparam>
 public EventToken SubscribeAsync <TEvent> (Func <TEvent, Task> action, ThreadMethod threadOption = ThreadMethod.PublisherThread, bool keepSubscriberReferenceAlive = false, Predicate <TEvent> filter = null)
 {
     return(new EventToken {
         Token = GetEvent <TEvent> ().Subscribe(action, (ThreadOption)threadOption, keepSubscriberReferenceAlive, filter)
     });
 }
Esempio n. 18
0
        public static IntPtr CreateThread(ThreadMethod startFunction, IntPtr threadParameter, uint creationFlags = 0)
        {
            uint dw;

            return(CreateThread(IntPtr.Zero, 0, startFunction, threadParameter, creationFlags, out dw));
        }
Esempio n. 19
0
 public Thread(string name, ThreadMethod trdinvoke)
 {
     this.name = name;
     trdman.Register(this);
     this.action = trdinvoke;
 }
Esempio n. 20
0
 public ThreadHandler(ThreadMethod method, int sleepMilliseconds)
     : this(method, sleepMilliseconds, false)
 {
 }