コード例 #1
0
        public void ReSpawn()
        {
            DictionaryEntry[] clone = new DictionaryEntry[threads.Count];
            threads.CopyTo(clone, 0);
            foreach (DictionaryEntry entry in clone)
            {
                (entry.Value as Tuple <Thread, ManualResetEvent>).Item2?.Set();

                ThreadDefinition threadDefinition = usedDefinitions.Find((ThreadDefinition obj) => obj.name.Equals(entry.Key));
                if (threadDefinition != null)
                {
                    usedDefinitions.Remove(threadDefinition);
                    threads.Remove(entry.Key);
                    Spawn(threadDefinition);
                }

                ParameterizedThreadDefinition parameterizedThreadDefinition = usedParameterizedDefinitions.Find((ParameterizedThreadDefinition obj) => obj.name.Equals(entry.Key));
                if (parameterizedThreadDefinition != null)
                {
                    usedParameterizedDefinitions.Remove(parameterizedThreadDefinition);
                    threads.Remove(entry.Key);
                    ManagedSpawn(parameterizedThreadDefinition);
                }
            }
        }
コード例 #2
0
        public void ManagedSpawn(ParameterizedThreadDefinition definition)
        {
            ManualResetEvent newLock = new ManualResetEvent(false);
            Thread           thread  = new Thread(definition.callback);

            thread.Start(newLock);
            usedParameterizedDefinitions.Add(definition);
            threads.Add(definition.name, new Tuple <Thread, ManualResetEvent>(thread, newLock));
        }
コード例 #3
0
        public void DeSpawn()
        {
            Tuple <Thread, ManualResetEvent> thread = (Tuple <Thread, ManualResetEvent>)threads[threads.Count - 1];

            thread.Item2?.Set();

            ThreadDefinition threadDefinition = usedDefinitions.Find((ThreadDefinition obj) => obj.name.Equals(thread.Item1.Name));

            if (threadDefinition != null)
            {
                usedDefinitions.Remove(threadDefinition);
                threads.Remove(thread.Item1.Name);
            }

            ParameterizedThreadDefinition parameterizedThreadDefinition = usedParameterizedDefinitions.Find((ParameterizedThreadDefinition obj) => obj.name.Equals(thread.Item1.Name));

            if (parameterizedThreadDefinition != null)
            {
                usedParameterizedDefinitions.Remove(parameterizedThreadDefinition);
                threads.Remove(thread.Item1.Name);
            }
        }