Esempio n. 1
0
        protected override void BackgroundWorkerDoWork(object sender, DoWorkEventArgs args)
        {
            List <ItemDataClass> itemDataClass = new List <ItemDataClass>();

            BackgroundWorker worker = (BackgroundWorker)sender;

            int simulationCount = _SettingItemData.Simulations.Count;
            int batchCount      = (simulationCount / ((MAX_BATCH))) + 1;

            Debug.WriteLine(batchCount + " :: " + simulationCount);
            for (int i = 0; i < batchCount; i++)
            {
                int modCount      = (simulationCount % MAX_BATCH);
                int maxBatchCount = (i + 1) * MAX_BATCH < simulationCount ? MAX_BATCH : modCount;

                ManualResetEvent[] manualResetEvents = new ManualResetEvent[maxBatchCount];
                SimulationThread[] simulationThreads = new SimulationThread[maxBatchCount];

                for (int j = 0; j < maxBatchCount; j++)
                {
                    int percentage = ((i * MAX_BATCH) + j) / simulationCount;
                    worker.ReportProgress(percentage);
                    string xmlURL = _SettingItemData.Url + _SettingItemData.Simulations[(i * MAX_BATCH) + j];
                    Debug.WriteLine(xmlURL);
                    manualResetEvents[j] = new ManualResetEvent(false);
                    SimulationThread simulationThread = new SimulationThread(j, _SettingItemData.Simulations[(i * MAX_BATCH) + j], xmlURL, manualResetEvents[j]);
                    simulationThreads[j] = simulationThread;
                    ThreadPool.QueueUserWorkItem(simulationThreads[j].ThreadPoolCallback, j);
                }

                WaitHandle.WaitAll(manualResetEvents);
                Debug.WriteLine("All Calculation are complete....");

                for (int j = 0; j < maxBatchCount; j++)
                {
                    SimulationThread simulationThread = simulationThreads[j];
                    List <string>    elementList      = simulationThread.ElementList;
                    string           simulationName   = simulationThread.SimulationName;

                    SimulationItemData simulationData = new SimulationItemData(simulationName, elementList);
                    itemDataClass.Add(simulationData);
                }
            }

            args.Result = itemDataClass;
        }
Esempio n. 2
0
        private void ProcessGithubSimulationData(BackgroundWorker worker, DoWorkEventArgs args)
        {
            try
            {
                List <ItemDataClass>           itemDataClass   = new List <ItemDataClass>();
                List <GithubSimulationDataURL> simulationsList = GetSimulationDataFromGithub().Result;
                int simulationsCount = simulationsList.Count;

                int maxBatchCount = simulationsCount;

                SimulationThread[] simulationThreads = new SimulationThread[maxBatchCount];

                for (int j = 0; j < maxBatchCount; j++)
                {
                    SimulationThread simulationThread = new SimulationThread(j, simulationsList[j].SimulationName, simulationsList[j].XMLURL);
                    simulationThreads[j] = simulationThread;
                }

                Debug.WriteLine("All Calculation are complete....");

                for (int j = 0; j < maxBatchCount; j++)
                {
                    SimulationThread simulationThread = simulationThreads[j];
                    List <string>    elementList      = simulationThread.ElementList;
                    string           simulationName   = simulationThread.SimulationName;

                    SimulationItemData simulationData = new SimulationItemData(simulationName, elementList);
                    itemDataClass.Add(simulationData);
                }



                args.Result = itemDataClass;
            }
            catch (Exception e)
            {
                Debug.WriteLine("Process Simulation Error :: " + e.Message + " : " + e.StackTrace);
            }
        }