Пример #1
0
        private void analysisThread(object moduleObj)
        {
            lock (this)
            {
                IModule module = moduleObj as IModule;
                if (module == null)
                {
                    throw new ArgumentException("Object needs to inherit from IModule");
                }

                List <Thread> threads = new List <Thread>();
                try
                {
                    bool saveMessages = StateMaster.getCacheMessages();

                    ConversationIterator messages = new ConversationIterator(m_conversationID, saveMessages);

                    if (!module.canParallelize())
                    {
                        m_sem.WaitOne();
                        foreach (FacebookMessage message in messages)
                        {
                            m_empty = false;
                            module.analyze(message);
                        }
                        m_sem.Release(1);
                    }
                    else
                    {
                        ParallelOptions po = new ParallelOptions();
                        Parallel.ForEach <FacebookMessage>(messages,
                                                           new Action <FacebookMessage>((FacebookMessage message) =>
                        {
                            m_empty = false;
                            module.parallelAnalyze(message);
                        }));
                    }

                    m_counterSem.Release(1);
                }
                catch (System.Threading.ThreadInterruptedException)
                {
                    if (module.canParallelize())
                    {
                        // TODO: Cleanup threads created in parallel version
                    }
                }
            }
        }