示例#1
0
            public void Start(Task task, int seconds)
            {
                Thread.Sleep((_delay + seconds) * 1000);
                var result = $"Task with type: {task} completed after {_delay + seconds} seconds from worker {_number}";

                WorkCompleted?.Invoke(result);
            }
示例#2
0
 public void DoWork()
 {
     DoingWork = true;
     DoWorkImplementation();
     DoingWork = false;
     WorkCompleted?.Invoke();
 }
示例#3
0
        private void Work()
        {
            if (workItems.Count == 0)
            {
                //Wait for signal
                //... Just to be sure!
                while (workItems.Count == 0)
                {
                    startSignal.WaitOne();
                }
            }

            while (workItems.Count > 0)
            {
                //Gets the item from queue, does its work & repeats
                var item = workItems.Dequeue();

                //Inform about the work
                WorkItemStarted?.Invoke(this, item);

                //Start the work
                item.Work.Invoke(this);

                //Inform about job being done
                WorkItemCompleted?.Invoke(this, item);
            }

            //Inform about DONE!
            WorkCompleted?.Invoke(this);
        }
示例#4
0
        protected virtual void OnWorkCompleted(int hours)
        {
            WorkPerformedEventArgs wpea = new WorkPerformedEventArgs {
                Hours = hours
            };

            WorkCompleted?.Invoke(this, wpea);
        }
示例#5
0
 public virtual void DoWork(int hours, WorkType workType)
 {
     for (int i = 0; i < hours; i++)
     {
         WorkPerformed.Invoke(i + 1, workType);
     }
     WorkCompleted.Invoke(this, new WorkCompletedEventsArgs(hours, workType));
 }
 public WorkCommandAgentObserver
 (
     WorkSubmitted <TSpec> WorkSubmitted,
     WorkDispatched <TSpec> WorkDispatched,
     WorkCompleted <TSpec> WorkCompleted
 ) : base
     (
         work => WorkSubmitted?.Invoke(work.Command),
         work => WorkDispatched?.Invoke(work.Command),
         work => WorkCompleted?.Invoke(work.Command)
     )
 {
 }
 public void DoWork(int hours, WorkType type)
 {
     for (int i = 0; i < hours; i++)
     {
         if (WorkPerformed != null)
         {
             WorkPerformed.Invoke(i + 1, type);
         }
     }
     if (WorkCompleted != null)
     {
         WorkCompleted.Invoke(this, new WorkCompletedEventArgs(hours, type));
     }
 }
示例#8
0
            public void Start(Task task, int seconds)
            {
                var totalseconds = _delay + seconds;

                for (var i = 0; i < totalseconds; i++)
                {
                    Thread.Sleep(1 * 1000);
                    WorkExecuting?.Invoke(this, EventArgs.Empty);
                }

                var args = new WorkCompletedEventArgs($"Task with type: {task} completed after {totalseconds} seconds from worker {_number}",
                                                      totalseconds);

                WorkCompleted?.Invoke(this, args);
            }
        // using the approach where you explicitly define a handler.
        //public event SubscribeNotifyHandler SubscribeToNotifications;
        //public delegate void SubscribeNotifyHandler(object sender, MyCustomEventArgs args);

        /// <summary>
        /// Do some work and when done, raise a notification.
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public int DoSomeWork(string str)
        {
            for (int i = 0; i < 5; i++)
            {
                System.Threading.Thread.Sleep(2000);
                Console.WriteLine($"\nIn DoSomeWork(): Raising OnWorkEventRaiser({str})");
                // raise the event which in turn will signal all the subscribers; can pass back
                // data in the CustomEventArgs
                SubscribeToNotifications?.Invoke(this, new MyCustomEventArgs("Responding to work done."));
            }

            // raise completion event
            WorkCompleted?.Invoke(this, new MyCustomEventArgs("Work has finished."));
            return(1);
        }
示例#10
0
 public WorkCommandAgentObserver
 (
     WorkGroupSubmitted GroupSubmitted     = null,
     WorkGroupCompleted GroupCompleted     = null,
     WorkSubmitted <TSpec> WorkSubmitted   = null,
     WorkDispatched <TSpec> WorkDispatched = null,
     WorkCompleted <TSpec> WorkCompleted   = null
 ) : base
     (
         GroupSubmitted,
         GroupCompleted,
         work => WorkSubmitted?.Invoke(work.Command),
         work => WorkDispatched?.Invoke(work.Command),
         work => WorkCompleted?.Invoke(work.Command)
     )
 {
 }
示例#11
0
        async Task BeginWork()
        {
            WorkBeginning?.Invoke("Bullshit", null);
            TotalRecordsToProcess = uow.Query <Location>().Count() +
                                    uow.Query <Cable>().Count() +
                                    uow.Query <Conduit>().Count() +
                                    uow.Query <MiscFacility>().Count();

            if (!string.IsNullOrWhiteSpace(TbCmsConnectionStringText) &&
                !string.IsNullOrWhiteSpace(tbOracleConnectionStringText))
            {
                await Task.WhenAll(
                    HandleStep2 <Location>("Locations"),
                    HandleStep2 <Cable>("Cables"),
                    HandleStep2 <Conduit>("Conduits"),
                    HandleStep2 <MiscFacility>("Miscfacilitys"));
            }
            WorkCompleted?.Invoke("No More Bullshit", null);
        }
示例#12
0
        public void DoWork(int hours, WorkType workType)
        {
            for (int i = 0; i < hours; i++)
            {
                if (workType == WorkType.Work)
                {
                    Console.WriteLine("$$$$$$$$$$$$$");
                }
                else if (workType == WorkType.DoNothing)
                {
                    Console.WriteLine("Zzzzz...");
                }

                //WorkPerfomed
                WorkPerfomed?.Invoke(this,
                                     new WorkInfo(workType, hours));
            }

            //WorkCompleted;
            WorkCompleted?.Invoke(this, EventArgs.Empty); //? - вызвать если не null
        }
示例#13
0
        public void DoWork(int hours, WorkType workType)
        {
            //if (WorkStarted != null)
            //	WorkStarted(hours, workType);

            WorkStarted?.Invoke(hours, workType);

            for (int i = 0; i < hours; i++)
            {
                System.Threading.Thread.Sleep(500);
                //if (WorkPieceDone != null)
                //	WorkPieceDone(i + 1, workType);
                //WorkPerformed?.Invoke(i + 1, workType);
                OnWorkPerformed(i + 1, workType);
            }
            //Console.WriteLine($"{i+1} hours done");

            //if (WorkCompleted != null)
            //	WorkCompleted(this, EventArgs.Empty);

            WorkCompleted?.Invoke(this, EventArgs.Empty);
        }
示例#14
0
        /// <summary>
        /// Simulates the employee working on a task.
        /// </summary>
        /// <returns>A <c>Task</c> with details of the operation.</returns>
        public virtual async Task DoWork()
        {
            /* This is one way of running an asynchronous operation. Program execution will
             * continue along while this completes on a separate thread.
             */
            await Task.Run(() =>
            {
                // Simulate doing your work here. A real-life scenario could be making a HTTP request or database query.
                Console.WriteLine($"{Name}: Doing my work now...");
                Thread.Sleep(5000);

                /* Fire the event, notifying all subscribers. This event handler will be null if no one
                 * is subscribing to it. Can also override the sender with any object or variable type.
                 */
                if (WorkCompleted != null)
                {
                    WorkCompleted.Invoke(Name, new WorkEventArgs("I've completed my work!"));
                }
                else
                {
                    Console.WriteLine($"{Name}: Moving on to something else now...");
                }
            });
        }
示例#15
0
 protected virtual void OnWorkCompleted(object sender, EventArgs e)
 {
     WorkCompleted?.Invoke(sender, e);
 }
 private void OnWorkerCompleted()
 {
     WorkCompleted?.Invoke(this, EventArgs.Empty);
     //if (WorkCompleted is EventHandler del)
     //    del(this, EventArgs.Empty);
 }
 private void ApplyQuery()
 {
     TweetSearcher.Query = Query;
     WorkCompleted?.Invoke(this, EventArgs.Empty);
 }
 private void Cancel()
 {
     WorkCompleted?.Invoke(this, EventArgs.Empty);
 }
示例#19
0
 protected virtual void OnWorkCompleted(object sender, EventArgs e)
 {
     WorkCompleted?.Invoke(this, EventArgs.Empty);
 }
示例#20
0
 public void OnWorkCompleted(bool cancelled) => WorkCompleted?.Invoke(cancelled);
示例#21
0
        public void Work()
        {
            mValidsKeywords   = CTL_Settings.KeywordsList.GetValidKeywordList();
            sStringComparison = CTL_Settings.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            List <CTL_TodoFile> fileObjectList = new List <CTL_TodoFile>();
            CTL_TodoFile        fileObject;

            sProgress_GetFileList  = 0;
            sProgress_ExcludePaths = 0;
            sProgress_ProcessFiles = 0;

            sFilesInProjectCount   = 0;
            sFilesProcessedCount   = 0;
            sCommentProcessedCount = 0;
            sTotalLinesCount       = 0;

            long time_RealStart             = CTL_Tools.ThreadSafeTimeStamp();
            long timeSpan_GetScriptFilePath = time_RealStart;
            long timeSpan_ProcessFiles      = 0;
            long time_StartProcessFiles     = 0;
            long timeSpan_ExcludeFiles      = 0;
            long time_StartExcludeFiles     = 0;

            long time_Start = time_RealStart;
            long time_Cur   = time_RealStart;


            ProcessChanged(0, 0, "Get files paths...");
            string[] scriptFilesPath = GetScriptFilesPath();
            sProgress_GetFileList = 1;
            sFilesInProjectCount  = scriptFilesPath.Length;


            if (CTL_Settings.DEBUG_MODE)
            {
                time_Cur = CTL_Tools.ThreadSafeTimeStamp();
                timeSpan_GetScriptFilePath = time_Cur - time_RealStart;
                time_StartExcludeFiles     = time_Cur;
            }


            //CTL...start exclude paths
            ProcessChanged(0, 0, "Exclude paths...");
            List <string> notExcludedPath = new List <string>(scriptFilesPath.Length);

            CTL_Settings.ExcludedPaths.GenerateOptimisedExcludeList();
            for (int i = 0; i < scriptFilesPath.Length; i++)
            {
                if (!CTL_Settings.ExcludedPaths.IsPathExcluded(scriptFilesPath[i], true))
                {
                    notExcludedPath.Add(scriptFilesPath[i]);
                }
                sProgress_ExcludePaths = (float)i / (float)scriptFilesPath.Length;
            }
            sProgress_ExcludePaths = 1;
            scriptFilesPath        = notExcludedPath.ToArray();
            //CTL...end exclude path


            if (CTL_Settings.DEBUG_MODE)
            {
                time_Cur = CTL_Tools.ThreadSafeTimeStamp();
                timeSpan_ExcludeFiles  = time_Cur - time_StartExcludeFiles;
                time_StartProcessFiles = time_Cur;
            }


            //CTL...start process files
            ProcessChanged(0, 0, "Process files...");
            for (int i = 0; i < scriptFilesPath.Length; i++)
            {
                if (mCanceled)
                {
                    break;
                }

                fileObject = ParseFileAtPath(scriptFilesPath[i]);
                if (fileObject != null)
                {
                    fileObjectList.Add(fileObject);
                }

                sProgress_ProcessFiles = (float)i / (float)scriptFilesPath.Length;
            }
            sProgress_ProcessFiles = 1;
            sFilesProcessedCount   = scriptFilesPath.Length;
            time_Cur = CTL_Tools.ThreadSafeTimeStamp();

            //CTL...end process  files
            if (CTL_Settings.DEBUG_MODE)
            {
                timeSpan_ProcessFiles = time_Cur - time_StartProcessFiles;
                Debug.Log("Refresh done in " + (time_Cur - time_RealStart) +
                          " -- GetScriptFilesPath: " + timeSpan_GetScriptFilePath +
                          " -- ExcludeFiles: " + timeSpan_ExcludeFiles +
                          " -- ProcessFiles: " + timeSpan_ProcessFiles +
                          "\nScript files in project: " + sFilesInProjectCount +
                          "\nScript files processed: " + sFilesProcessedCount +
                          "\nComments processed: " + sCommentProcessedCount +
                          "\nTotal lines count: " + sTotalLinesCount);
            }

            ProcessChanged(scriptFilesPath.Length, scriptFilesPath.Length, "COMPLETE");
            WorkCompleted.Invoke(fileObjectList, mCanceled);
        }
示例#22
0
 protected virtual void OnWorkCompleted()
 {
     WorkCompleted?.Invoke(this, EventArgs.Empty);
 }
示例#23
0
 public void OnWorkCompleted(object canceled)
 {
     WorkCompleted?.Invoke((bool)canceled);
 }