void _syncThread_OnError(SynchThreadErrorArgs args)
 {
     HandleError(args.Error);
 }
Пример #2
0
        /// <summary>
        /// Questa è la funzione che il thread dovrà eseguire.
        /// </summary>
        private void Run()
        {
            while (!_switchOff)
            {
                while (!ApplicationState.Instance.STEnabled)
                {
                    lock (ApplicationState.Instance)
                    {
                        Monitor.Wait(ApplicationState.Instance);
                    }
                }
                _currentAction = PendingActions.Instance.GetJob();
                try
                {

                    if (_currentAction.Handle())
                    {
                        lock (_currentAction)
                        {
                            PendingActions.Instance.SetDone(_currentAction);
                            if (OnActionPerformed != null)
                                OnActionPerformed(new SynchThreadActionPerformedArgs(_currentAction));
                        }
                    }
                }
                catch (Exception e)
                {
                    // TODO log
                    // Notifica che è accadeuto un errore se qualcuno si è registrato all'evento.
                    if (OnError != null)
                    {
                        SynchThreadErrorArgs args = new SynchThreadErrorArgs(e, _currentAction);
                        OnError(args);
                    }
                }
                finally {
                    if (_currentAction != null)
                    {
                        _currentAction.SetEnd();
                        _currentAction = null;
                    }
                }
            }
        }