private void ElementOnComplete(object sender, XMLParsingEventArgs args)
        {
            List <ItemDataClass> elementItemData = args._ItemDataClass;

            foreach (ItemDataClass element in elementItemData)
            {
                SimulationItemData simulationData = element as SimulationItemData;
                _SimulationItemData.Add(simulationData);
            }

            searchButton.Enabled = true;
            pictureBox2.Enabled  = false;
            pictureBox2.Visible  = false;
            //AssetsList.Text = "Data Is Ready";
            this.Cursor = Cursors.Default;
        }
Esempio n. 2
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;
        }