Beispiel #1
0
		//public void RunTasks()
		//{
		//    WorkerTaskInfo objThreadTaskInfo = null;
		//    WorkerTask workerTask = null;
		//    Thread processingThread = null;
		//    ArrayList colWorkerThreads = new ArrayList();
		//    int intNoOfBatchesPerThread = 0;
		//    int intEstimatedNoOfItemsPerThread = 0;

		//    if (mobjTaskInfo.BatchInformation.ItemCount <= mobjTaskInfo.BatchSize)
		//    {
		//        mobjTaskInfo.NoOfThreadsToUse = 1;
		//    }
		//    else
		//    {
		//        mobjTaskInfo.NoOfBatchesRequired = (mobjTaskInfo.BatchInformation.ItemCount / mobjTaskInfo.BatchSize) + 1;
		//        intNoOfBatchesPerThread = (mobjTaskInfo.NoOfBatchesRequired / mobjTaskInfo.NoOfThreadsToUse) + 1;
		//        intEstimatedNoOfItemsPerThread = intNoOfBatchesPerThread * mobjTaskInfo.BatchSize;
		//    }

		//    for (int intIndex = 0; intIndex < mobjTaskInfo.NoOfThreadsToUse; intIndex++)
		//    {
		//        // Create TaskInfo for individual Thread to process
		//        objThreadTaskInfo = new WorkerTaskInfo();
		//        // Common to all Threads
		//        objThreadTaskInfo.MethodInformation = mobjTaskInfo.MethodInformation;
		//        objThreadTaskInfo.BatchSize = mobjTaskInfo.BatchSize;
		//        objThreadTaskInfo.NoOfBatchesRequired = intNoOfBatchesPerThread;
		//        // Thread specific
		//        objThreadTaskInfo.BatchInformation.ItemCount = intEstimatedNoOfItemsPerThread;
		//        objThreadTaskInfo.BatchInformation.StartOfRange = mobjTaskInfo.BatchInformation.StartOfRange;
		//        objThreadTaskInfo.BatchInformation.EndOfRange = mobjTaskInfo.BatchInformation.StartOfRange + intEstimatedNoOfItemsPerThread;
		//        // Create new Task on own Thread to perform the process
		//        workerTask = new WorkerTask(objThreadTaskInfo);
		//        WireEvents(workerTask);
		//        mcolTasks.Add(workerTask);
		//        processingThread = new Thread(new ThreadStart(workerTask.DoWork));
		//        colWorkerThreads.Add(processingThread);
		//        // Increment Range Information that will be used for next Task required (if NoThreadsToUse > 1)
		//        mobjTaskInfo.BatchInformation.StartOfRange += (intEstimatedNoOfItemsPerThread + 1); // + 1 allows for BETWEEN query in SQL
		//    }

		//    // Start the Tasks
		//    int intThreadCounter = 1;
		//    foreach (Thread workerThread in colWorkerThreads)
		//    {
		//        workerThread.Start();
		//        // Logging (Optional)
		//        if (ConfigurationManager.AppSettings.Get("LoggingMode") == "verbose")
		//        {
		//            Logging.WriteToLog(this, "Worker Process started on Thread{" + intThreadCounter.ToString() + "}" + " " + "Batches Per Thread=" + intNoOfBatchesPerThread.ToString() + " " + "Batch Size " + mobjTaskInfo.BatchSize.ToString());
		//            intThreadCounter += 1;
		//        }
		//        IsBusy = true; // Must be set as soon as one Task has been started
		//    }

		//}

		private void WireEvents(WorkerTask workerTask)
		{
			// Wire Server instance to call Service copy of method for OnCallback
			workerTask.OnCallback -= new WorkerTask.ParentCallback(workerTask.InvokeParentCallback);
			workerTask.OnCallback += new WorkerTask.ParentCallback(this.InvokeParentCallback);

			// Wire child Server class to Pass Exceptions up to Service instance 
			workerTask.OnException -= new WorkerTask.HandleException(workerTask.InvokeHandleException);
			workerTask.OnException += new WorkerTask.HandleException(this.InvokeHandleException);
		}
Beispiel #2
0
		public void RunTasks()
		{
			WorkerTaskInfo objThreadTaskInfo = null;
			WorkerTask workerTask = null;
			int intNoOfBatchesPerThread = 1;    // 1 - If no Range Info is single call
            int intEstimatedNoOfItemsPerThread = 1; // 1 - If no Range Info is single call

			if (mobjTaskInfo.BatchInformation.ItemCount <= mobjTaskInfo.BatchSize)
			{
				mobjTaskInfo.NoOfThreadsToUse = 1;
			}
			else
			{
				mobjTaskInfo.NoOfBatchesRequired = (mobjTaskInfo.BatchInformation.ItemCount / mobjTaskInfo.BatchSize) + 1;
				intNoOfBatchesPerThread = (mobjTaskInfo.NoOfBatchesRequired / mobjTaskInfo.NoOfThreadsToUse) + 1;
				intEstimatedNoOfItemsPerThread = intNoOfBatchesPerThread * mobjTaskInfo.BatchSize;
			}

			for (int intIndex = 0; intIndex < mobjTaskInfo.NoOfThreadsToUse; intIndex++)
			{
				try
				{
                    //lock (lockingObject)
                    //{
						// Create TaskInfo for individual Thread to process
						objThreadTaskInfo = new WorkerTaskInfo();
						// Common to all Threads
						objThreadTaskInfo.MethodInformation = mobjTaskInfo.MethodInformation;
						objThreadTaskInfo.BatchSize = mobjTaskInfo.BatchSize;
						objThreadTaskInfo.NoOfBatchesRequired = intNoOfBatchesPerThread;
						// Thread specific
						objThreadTaskInfo.BatchInformation.ItemCount = intEstimatedNoOfItemsPerThread;
						objThreadTaskInfo.BatchInformation.StartOfRange = mobjTaskInfo.BatchInformation.StartOfRange;
						objThreadTaskInfo.BatchInformation.EndOfRange = mobjTaskInfo.BatchInformation.StartOfRange + intEstimatedNoOfItemsPerThread;
						// Create new Task on own Asynch Thread to perform the process
						workerTask = new WorkerTask(objThreadTaskInfo);
						WireEvents(workerTask);
						mcolTasks.Add(workerTask);
						WorkerTask.DoWorkPointer objMethodPointer = new WorkerTask.DoWorkPointer(workerTask.DoWork);
						// Start Task
						objMethodPointer.BeginInvoke(null, null);
					//}
				}
				catch (Exception excE)
				{
					OnException(this, excE);
				}
				finally
				{
					//// Unlock the main TaskInfo instances
					//Monitor.Exit(mobjTaskInfo);
				}
				// Logging (Optional)
				if (ConfigurationManager.AppSettings.Get("LoggingMode") == "verbose")
				{
					Logging.WriteToLog(this, "Worker Process started on Thread{" + intIndex.ToString() + "}" + " " + "Batches Per Thread=" + intNoOfBatchesPerThread.ToString() + " " + "Batch Size " + mobjTaskInfo.BatchSize.ToString());
				}
				// Increment Range Information that will be used for next Task required (if NoThreadsToUse > 1)
				mobjTaskInfo.BatchInformation.StartOfRange += (intEstimatedNoOfItemsPerThread + 1); // + 1 allows for BETWEEN query in SQL
			}
		}