コード例 #1
0
 private void SingleThreadWriteJob(int runs, int noOfThreads, int noOfIteractionsPerThread)
 {
     ThreadData tData;
     for (int i = 0; i < runs; i++)
     {
         if (i != runs - 1 && noOfIteractionsPerThread > 2)
         {
             tData = new ThreadData(ref _mut, ref _activeSheet, i + 2, ((i + 2) % noOfIteractionsPerThread == 2) || ((i + 2) % noOfIteractionsPerThread == 1), 0);
         }
         else
         {
             tData = new ThreadData(ref _mut, ref _activeSheet, i + 2, true, 0);
         }
         tData.SetIndex(i + 2);
         Worker0(tData);
     }
 }
コード例 #2
0
        private void RunSampleCode()
        {
            SetActiveSheet();

            int noOfRuns    = 50;
            int noOfThreads = 5;
            int noOfIteractionsPerThread = 10;

            System.Windows.Forms.MessageBox.Show("Starting MultiThreaded write job, writing " + noOfRuns + " cells.");
            _activeSheet.Cells[1, 1] = "MultiThread Write BatchID";
            _activeSheet.Cells[1, 2] = "MultiThread Write IndexID";
            _activeSheet.Cells[1, 3] = "MultiThread Write IndexCalculation";
            _activeSheet.Cells[1, 4] = "MultiThread Write Search State";
            _activeSheet.Cells[1, 5] = "MultiThread Write BatchTime (Start/End)";

            _activeSheet.Cells[1, 6]  = "SingleThread Read BatchID";
            _activeSheet.Cells[1, 7]  = "SingleThread Read IndexID";
            _activeSheet.Cells[1, 8]  = "SingleThread Write IndexCalculation";
            _activeSheet.Cells[1, 9]  = "SingleThread Read Search State";
            _activeSheet.Cells[1, 10] = "SingleThread Read BatchTime (Start/End)";
            MultiThreadWriteJob(noOfRuns, noOfThreads, noOfIteractionsPerThread);
            long jobExecCount = 0;

            while (jobExecCount < noOfRuns)
            {
                if (_mut.WaitOne())
                {
                    // System.Windows.Forms.MessageBox.Show("Read job, jobExecCount:" + jobExecCount.ToString());
                    jobExecCount = ThreadData.GetJobExecWaitCount();
                    _mut.ReleaseMutex();
                }
            }
            if (_mut.WaitOne())
            {
                System.Windows.Forms.MessageBox.Show("Starting SingleThreaded read job, reading " + noOfRuns + " cells.");
                _mut.ReleaseMutex();
            }
            //reset and start read job
            jobExecCount = 0;
            ThreadData.ResetJobExecWaitCount();
            SingleThreadWriteJob(noOfRuns, noOfThreads, noOfIteractionsPerThread);
            _activeSheet.Cells[noOfRuns + 2, 5] = "=MIN(E2:E" + (noOfRuns + 1).ToString() + ")";
            _activeSheet.Cells[noOfRuns + 3, 5] = "=MAX(E2:E" + (noOfRuns + 1).ToString() + ")";
            _activeSheet.Cells[noOfRuns + 4, 4] = "Run Time in milliseconds:";
            _activeSheet.Range[_activeSheet.Cells[noOfRuns + 4, 4], _activeSheet.Cells[noOfRuns + 4, 4]].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight;
            _activeSheet.Cells[noOfRuns + 4, 5] = "=(E" + (noOfRuns + 3).ToString() + "-E" + (noOfRuns + 2).ToString() + ")*24*60*60*1000";
            _activeSheet.Cells[noOfRuns + 5, 4] = "Run Time in seconds:";
            _activeSheet.Range[_activeSheet.Cells[noOfRuns + 5, 4], _activeSheet.Cells[noOfRuns + 5, 4]].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight;
            _activeSheet.Cells[noOfRuns + 5, 5] = "=(E" + (noOfRuns + 3).ToString() + "-E" + (noOfRuns + 2).ToString() + ")*24*60*60";

            _activeSheet.Cells[noOfRuns + 2, 10] = "=MIN(J2:J" + (noOfRuns + 1).ToString() + ")";
            _activeSheet.Cells[noOfRuns + 3, 10] = "=MAX(J2:J" + (noOfRuns + 1).ToString() + ")";
            _activeSheet.Cells[noOfRuns + 4, 9]  = "Run Time in milliseconds:";
            _activeSheet.Range[_activeSheet.Cells[noOfRuns + 4, 9], _activeSheet.Cells[noOfRuns + 4, 9]].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight;
            _activeSheet.Cells[noOfRuns + 4, 10] = "=(J" + (noOfRuns + 3).ToString() + "-J" + (noOfRuns + 2).ToString() + ")*24*60*60*1000";
            _activeSheet.Cells[noOfRuns + 5, 9]  = "Run Time in seconds:";
            _activeSheet.Range[_activeSheet.Cells[noOfRuns + 5, 9], _activeSheet.Cells[noOfRuns + 5, 9]].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight;
            _activeSheet.Cells[noOfRuns + 5, 10] = "=(J" + (noOfRuns + 3).ToString() + "-J" + (noOfRuns + 2).ToString() + ")*24*60*60";

            _activeSheet.Cells.Columns.AutoFit();
            _activeSheet.Cells.Rows.AutoFit();
            _activeSheet.Range[_activeSheet.Cells[1, 1], _activeSheet.Cells[1, 10]].EntireRow.Font.Bold = true;
            System.Windows.Forms.MessageBox.Show("All jobs completed.");
        }
コード例 #3
0
 private void MultiThreadWriteJob(int runs, int noOfThreads, int noOfIteractionsPerThread)
 {
     ThreadData tData;
     ThreadPool.SetMaxThreads(noOfThreads, noOfThreads);
     int j = 0;
     for (int i = 0; i < runs; i = i + noOfIteractionsPerThread)
     {
         if (i + noOfIteractionsPerThread < runs)
         {
             tData = new ThreadData(ref _mut, ref _activeSheet, i + 2, (long)i + 2 + noOfIteractionsPerThread, j);
         }
         else
         {
             tData = new ThreadData(ref _mut, ref _activeSheet, i + 2, (long)2 + runs, j);
         }
         ThreadPool.QueueUserWorkItem(new WaitCallback(Worker1), tData);
         j++;
     }
 }