Esempio n. 1
0
		public void DoWork()
        {
            WorkerTaskInfo objThreadTaskInfo = new WorkerTaskInfo();
			AssemblyContainer objExecutor = null;
            int intBatchCounter = 0;

            // Create TaskInfo instance for use by each individual Batch
            objThreadTaskInfo = new WorkerTaskInfo();
            // Common to all Batches
            objThreadTaskInfo.MethodInformation = mobjTaskInfo.MethodInformation;
            // Starting Range and per Batch ItemCount
			objThreadTaskInfo.BatchSize = mobjTaskInfo.BatchSize;
			objThreadTaskInfo.BatchInformation.StartOfRange = mobjTaskInfo.BatchInformation.StartOfRange;
            objThreadTaskInfo.BatchInformation.EndOfRange = mobjTaskInfo.BatchInformation.StartOfRange + mobjTaskInfo.BatchSize;

            while (intBatchCounter < mobjTaskInfo.NoOfBatchesRequired)
            {
				// Perform Work
				if (HasStopWorkRequestBeenReceived == true)
				{
					IsBusy = false;
					OnCallback(this, "Thread received Stop request (BatchCounter=" + intBatchCounter.ToString() + ")");
					return;
				}
				// Logging (Optional)
				if (ConfigurationManager.AppSettings.Get("LoggingMode") == "verbose")
				{
					Logging.WriteToLog(this, "Commencing Batch {" + intBatchCounter.ToString() + "}" + " " + "Start of Range = " + mobjTaskInfo.BatchInformation.StartOfRange.ToString());
				}
				try
				{
					// Dynamically Invoke Method for current Batch
					objExecutor = new AssemblyContainer();
                    objExecutor.ExecuteMethod(objThreadTaskInfo);
                    // Prepare to Invoke Method for next Batch
                    objThreadTaskInfo.BatchInformation.StartOfRange += (objThreadTaskInfo.BatchSize + 1); // + 1 assumes a BETWEEN query in SQL
                    objThreadTaskInfo.BatchInformation.EndOfRange = objThreadTaskInfo.BatchInformation.StartOfRange + objThreadTaskInfo.BatchSize;
                    intBatchCounter += 1; // Increment Batch Counter
				}
				catch (Exception excE)
				{
					OnException(this, excE);
					return;
				}
				finally
				{
					//System.Threading.Monitor.Exit(objExecutor);
				}
			}

			// End Work
			IsBusy = false;
			OnCallback(this, "Thread completed its work (BatchCounter=" + intBatchCounter.ToString() + ")");
		}
Esempio n. 2
0
		public WorkerProcess(WorkerTaskInfo taskInfo)
		{
			mobjTaskInfo=taskInfo;
		}
Esempio n. 3
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
			}
		}
Esempio n. 4
0
		public WorkerTask(WorkerTaskInfo taskInfo)
        {
			mobjTaskInfo = taskInfo;
        }