예제 #1
0
        // A callback is a function that will be called when a process is done executing
        // a specific task
        public static void Run()
        {
            // To create a callback, a function address needs to be stored in a variable
            WorkCompletedCallBack callBack = TestCallBack;

            DoWork(callBack);

            DoMoreWork(Console.WriteLine);

            // Delegates (see below)
            // ------------------------------------------------------
            Foo fooExample = Bar;
            var time       = fooExample(DateTime.UtcNow);

            Console.WriteLine(time);

            // Action delegate (see below)
            // ------------------------------------------------------
            // Named method
            NamedActionDelegate = NamedMethod;
            NamedActionDelegate?.Invoke("Named Action Delegate", 5);

            // Anonymous function
            AnonymousActionDelegate?.Invoke("Anonymous Action Delegate", 106);

            // Func delegate (see below)
            // ------------------------------------------------------
            NamedFuncDelegate = NamedMethod;
            var namedResult = NamedFuncDelegate?.Invoke(100);

            Console.WriteLine(namedResult);
        }
 public SearchProductPresenter(IStateManager manager, WorkCompletedCallBack callBack) : base(manager)
 {
     Form           = (ISearchProductView)FormFactory.CreateForm("SearchProductForm", new object[] { this });
     ProductSection = new ProductSection(Form.ProductDataTable, this, Form);
     Form.SetSearchParams(ProductSection.GetSearchParameters());
     ProductSection.UpdateVisibleProducts();
     Callback  = callBack;
     Form.Text = Title;
 }
예제 #3
0
 public Event(int execTimeout, WorkCompletedCallBack callback, IEventManager manager, bool isOneTimeOnly)
 {
     Callback         = callback;
     _accumulatedTime = 0;
     _maxCounterValue = execTimeout;
     Id             = ++ID;
     _isOneTimeOnly = isOneTimeOnly;
     Manager        = manager;
 }
예제 #4
0
 public ConfirmActionPresenter(IStateManager manager, WorkCompletedCallBack callBack, string confirmText) :
     base(manager)
 {
     Form = (IConfirmActionView)FormFactory.CreateForm("ConfirmActionForm", new object[] { this });
     ((Form)Form).FormClosing += (o, e) => Cancel();
     Form.ConfirmTextContent   = confirmText;
     CallBack           = callBack;
     IsConfirmPerformed = false;
     Form.Text          = @"Потвърждаване";
 }
        private void NotifyWorkCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
        {
            WorkCompletedCallBack workCompletedCopy = _workCompleted;

            if (workCompletedCopy != null)
            {
                workCompletedCopy(_workReportCreator.GenerateReport());
            }

            _bgWorker.RunWorkerCompleted -= NotifyWorkCompleted;
            _bgWorker.DoWork             -= RunWorker;

            _cancelRequested = false;
            _undoStack.Clear();
            _commandQueue.Clear();
        }
예제 #6
0
 private void WorkCompleted()
 {
     if (this.aisinoDataGrid1.InvokeRequired || this.toolStrip1.InvokeRequired)
     {
         WorkCompletedCallBack method = new WorkCompletedCallBack(this.WorkCompleted);
         this.aisinoDataGrid1.Invoke(method, new object[0]);
     }
     else
     {
         for (int i = 0; i < this.aisinoDataGrid1.ColumnCount; i++)
         {
             this.aisinoDataGrid1.AutoResizeColumn(i);
         }
         this.toolStripBtnDBPath.Enabled = true;
         this.toolStripBtnDBFile.Enabled = true;
     }
 }
예제 #7
0
 public void ConfirmOrder(WorkCompletedCallBack callback)
 {
     callback(this.orders.ToArray());
     this.orders.Clear();
 }
예제 #8
0
 public static void DoWork(WorkCompletedCallBack callBack)
 {
     callBack("Hello world!");
 }