Пример #1
0
        private void timer1_Tick(object sender)
        {
            CountDown--;

            if (CountDown == 0)
            {
                KeepAllOrdersOn();
                if (UpdateLockingEvent != null)
                {
                    Delegate[] invkList = UpdateLockingEvent.GetInvocationList();

                    //foreach (ChangeDelegate handler in invkList)
                    foreach (var @delegate in invkList)
                    {
                        var handler  = (UpdateTimerLockingDelegate)@delegate;
                        var handler1 = handler;
                        new Thread(() =>
                        {
                            try
                            {
                                handler1(false);
                                Debug.WriteLine("Invoking event handler");
                            }
                            catch (Exception)
                            {
                                UpdateLockingEvent -= handler1;
                                Debug.WriteLine("Exception: Removed an event handler");
                            }
                        }).Start();
                    }
                }
                _timer.Dispose();
            }
        }
Пример #2
0
        private void SetTimer()
        {
            Debug.WriteLine("setting Timer");

            if (UpdateLockingEvent != null)
            {
                Delegate[] invkList = UpdateLockingEvent.GetInvocationList();

                //foreach (ChangeDelegate handler in invkList)
                foreach (var @delegate in invkList)
                {
                    var handler  = (UpdateTimerLockingDelegate)@delegate;
                    var handler1 = handler;
                    new Thread(() =>
                    {
                        try
                        {
                            handler1(true);
                            Debug.WriteLine("Invoking event handler");
                        }
                        catch (Exception)
                        {
                            UpdateLockingEvent -= handler1;
                            Debug.WriteLine("Exception: Removed an event handler");
                        }
                    }).Start();
                }
            }

            CountDown = Constants.TimerSeconds;
            _timer    = new Timer(timer1_Tick, null, 0, 1000);
        }