Ejemplo n.º 1
0
        public FusionProgressDialog(WorkerDelegate del)
        {
            InitializeComponent();

            Worker = del;
            Shown += FusionProgressDialog_Shown;
        }
Ejemplo n.º 2
0
        public ProgressPopup(WorkerDelegate worker)
        {
            InitializeComponent();

            this.worker     = worker;
            trackableWorker = null;
        }
Ejemplo n.º 3
0
        public ProgressPopup(TrackableWorkerDelegate trackableWorker)
        {
            InitializeComponent();

            worker = null;
            this.trackableWorker = trackableWorker;
        }
        public ProgressPopup(WorkerDelegate worker)
        {
            InitializeComponent();

            this.worker = worker;
            trackableWorker = null;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GPodder.PortaPodder.BackgroundWorker"/> class.
 /// </summary>
 /// <param name='worker'>Worker.</param>
 public BackgroundWorker(WorkerDelegate worker)
 {
     if(worker == null) {
     throw new ArgumentException("Worker delegate cannot be null");
       }
       this.worker = worker;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Run code in a new worker thread. WorkerDelegate should return true to end, false to repeat.
        /// </summary>
        /// <param name="worker">Delegate to be run</param>
        public void Start(WorkerDelegate worker)
        {
            if (IsRunning)
                return;

            var frame = new StackFrame(1);
            var method = frame.GetMethod();
            var type = method.DeclaringType;
            var ns = type != null ? type.Namespace : string.Empty;

            _worker = worker;
            _thread = new Thread(SafeWorkerDelegate)
            {
                Name = string.Format("Worker: {0}.{1}", ns, type),
                IsBackground = true,
                Priority = ThreadPriority.BelowNormal,
            };

            Logger.Debug("Starting {0} Thread Id={1}", _thread.Name, _thread.ManagedThreadId);

            _working = true;
            _thread.Start();

            OnStarted.Invoke();
        }
        public ProgressPopup(TrackableWorkerDelegate trackableWorker)
        {
            InitializeComponent();

            worker = null;
            this.trackableWorker = trackableWorker;
        }
Ejemplo n.º 8
0
        internal bool InvokeAsyncCore(T arg, bool isTry)
        {
            lock (this) {
                if (_isBusy)
                {
                    if (isTry)
                    {
                        return(false);
                    }
                    else
                    {
                        throw new InvalidOperationException("Operation is still executing");
                    }
                }
                _isBusy = true;
            }
            _isCancelled = false;
            AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(null);
            WorkerDelegate worker  = new WorkerDelegate(Worker);

            worker.BeginInvoke(arg, asyncOp, null, null);

            if (this.TimeoutMilliseconds > 0)
            {
                _timeoutTimer = new Timer(TimeoutCallback, asyncOp, this.TimeoutMilliseconds, Timeout.Infinite);
            }

            return(true);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Run code in a new worker thread. WorkerDelegate should return true to end, false to repeat.
        /// </summary>
        /// <param name="worker">Delegate to be run</param>
        public void Start(WorkerDelegate worker)
        {
            if (IsRunning)
            {
                return;
            }

            var frame  = new StackFrame(1);
            var method = frame.GetMethod();
            var type   = method.DeclaringType;
            var ns     = type != null ? type.Namespace : string.Empty;

            _worker = worker;
            _thread = new Thread(SafeWorkerDelegate)
            {
                Name         = string.Format("Worker: {0}.{1}", ns, type),
                IsBackground = true,
                Priority     = ThreadPriority.BelowNormal,
            };

            Logger.Debug("Starting {0} Thread Id={1}", _thread.Name, _thread.ManagedThreadId);

            _working = true;
            _thread.Start();

            OnStarted.Invoke();
        }
Ejemplo n.º 10
0
		///<summary>Adds a delegate that will be called every time a new ODThread is created. Useful for assigning thread static variables from one
		///thread to another.</summary>
		///<param name="runsOnParentThread">This Func will run on the thread that creates the new thread.</param>
		///<param name="runsOnChildThread">This Action takes in the result from the Func and runs on the new thread that is created.</param>
		public static void AddInitializeHandler<T>(Func<T> runsOnParentThread,Action<T> runsOnChildThread) {
			_onInitialize+=(ODThread o) => {
				T t=runsOnParentThread();
				o._setupHandler+=(ODThread od) => {
					runsOnChildThread(t);
				};
			};
		}
Ejemplo n.º 11
0
        /// <summary>
        /// Run a delegate passed by the caller in the GenericWrapper's AppDomain. The delegate will receive
        /// this object and the "state" parameter passed by the caller. This allows caller code to perform
        /// tasks that access the value many times without marshaling across AppDomains every time.
        /// </summary>
        public object RunCustomWorker(WorkerDelegate worker, object state)
        {
            if (worker == null)
            {
                throw new ArgumentNullException("worker");
            }

            return(worker(this, state));
        }
Ejemplo n.º 12
0
Archivo: ODThread.cs Proyecto: mnisl/OD
		///<summary>Creates a thread that will continue to run the WorkerDelegate after Start() is called and will stop running once one of the quit methods has been called or the application itself is closing.  timeIntervalMS (in milliseconds) determines how long the thread will wait before executing the WorkerDelegate again.  Set timeIntervalMS to zero or a negative number to have the WorkerDelegate only execute once and then quit itself.</summary>
		public ODThread(int timeIntervalMS,WorkerDelegate worker,params object[] parameters) {
			lock(_lockObj) {
				_listOdThreads.Add(this);
			}
			_thread=new Thread(new ThreadStart(this.Run));
			TimeIntervalMS=timeIntervalMS;
			_worker+=worker;
			Parameters=parameters;
		}
Ejemplo n.º 13
0
        private void reloadDefaultSourcesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            WorkerDelegate worker = new WorkerDelegate(MovingPicturesCore.DataProviderManager.LoadInternalProviders);
            ProgressPopup  popup  = new ProgressPopup(worker);

            popup.Owner = this.ParentForm;
            popup.ShowDialog();

            reloadList();
        }
Ejemplo n.º 14
0
 public WorkerThread(WorkerDelegate worker, Control parent)
 {
     AbortRequest    = false;
     Parent          = parent;
     Worker          = worker;
     RefreshTime     = 500;
     IsSuccessful    = false;
     m_LastUpdateGui = DateTime.MinValue;
     ThreadUtils.SetClientCultureInfo();
 }
Ejemplo n.º 15
0
 ///<summary>Creates a thread that will continue to run the WorkerDelegate after Start() is called and will stop running once one of the quit methods has been called or the application itself is closing.  timeIntervalMS (in milliseconds) determines how long the thread will wait before executing the WorkerDelegate again.  Set timeIntervalMS to zero or a negative number to have the WorkerDelegate only execute once and then quit itself.</summary>
 public ODThread(int timeIntervalMS, WorkerDelegate worker, params object[] parameters)
 {
     lock (_lockObj) {
         _listOdThreads.Add(this);
     }
     _thread        = new Thread(new ThreadStart(this.Run));
     TimeIntervalMS = timeIntervalMS;
     _worker       += worker;
     Parameters     = parameters;
 }
Ejemplo n.º 16
0
        private static void TimeIt(WorkerDelegate worker)
        {
            var startTime = DateTime.Now;
            var stopTime  = DateTime.Now;

            worker();
            var duration = stopTime - startTime;

            Console.WriteLine($"Elapsed time: {duration}");
        }
Ejemplo n.º 17
0
        public override void Execute(IrcEventArgs e)
        {
            Interlocked.Increment(ref counter);

            WorkerDelegate worker = new WorkerDelegate(Worker);
            AsyncCallback completedCallback = new AsyncCallback(CommandCompletedCallback);

            AsyncOperation async = AsyncOperationManager.CreateOperation(null);
            worker.BeginInvoke(e, completedCallback, async);
        }
Ejemplo n.º 18
0
        private ArrayList messageList;          //  the list of messages that BizTalk gives us to process

        public TransactionalAsyncBatch(IBTTransportProxy transportProxy, ControlledTermination control, string propertyNamespace, int maxBatchSize)
        {
            this.worker      = new WorkerDelegate(Worker);
            this.batchWorker = new BatchWorkerDelegate(BatchWorker);

            this.transportProxy    = transportProxy;
            this.control           = control;
            this.propertyNamespace = propertyNamespace;
            this.maxBatchSize      = maxBatchSize;
            this.messageList       = new ArrayList();
        }
Ejemplo n.º 19
0
        public static void ShowDialog(WorkerDelegate del)
        {
            if (del == null)
                throw new ArgumentNullException("del");

            PluginDialog.ExecuteOnSTAThread(delegate(object delegateObj)
            {
                using (FusionProgressDialog dlg = new FusionProgressDialog((WorkerDelegate)delegateObj))
                    dlg.ShowDialog();
            }, del);
        }
Ejemplo n.º 20
0
		///<summary>Creates a thread that will continue to run the WorkerDelegate after Start() is called and will stop running once one of the quit methods has been called or the application itself is closing.  timeIntervalMS (in milliseconds) determines how long the thread will wait before executing the WorkerDelegate again.  Set timeIntervalMS to zero or a negative number to have the WorkerDelegate only execute once and then quit itself.</summary>
		public ODThread(int timeIntervalMS,WorkerDelegate worker,params object[] parameters) {
			//The very first thing to do is give the calling method a chance to pass along their current database context to this thread.
			if(GetDatabaseContextParent!=null) {
				_databaseContext=GetDatabaseContextParent();//Store the database context from the parent to utilize within Run().
			}
			lock(_lockObj) {
				_listOdThreads.Add(this);
			}
			_thread=new Thread(new ThreadStart(this.Run));
			TimeIntervalMS=timeIntervalMS;
			_worker+=worker;
			Parameters=parameters;
			_onInitialize?.Invoke(this);
		}
Ejemplo n.º 21
0
        public void InvokeAsync(T arg, object userState)
        {
            AsyncOperation asyncOp;

            lock (_userStateToLifetime.SyncRoot) {
                if (_userStateToLifetime.Contains(userState))
                {
                    throw new ArgumentException("userState must be unique");
                }
                asyncOp = AsyncOperationManager.CreateOperation(userState);
                _userStateToLifetime[userState] = asyncOp;
            }
            WorkerDelegate worker = new WorkerDelegate(Worker);

            worker.BeginInvoke(arg, asyncOp, null, null);
        }
Ejemplo n.º 22
0
        public MainWindow()
        {
            InitializeComponent();
            InitializeNotifyIcon();
            InitializeLogger(logText);

            var logDirs = new List<string>();
            DirFinder[] dirFinders = { new RegistryDirFinder(Registry.CurrentUser, "Software\\Riot Games\\RADS", "LocalRootFolder")
                                     , new RegistryDirFinder(caHive, caKey, caValue)
                                     , new StaticDirFinder("C:\\Riot Games\\League of Legends")
                                     , new DialogDirFinder()
                                     };

            var dirSrcs = new List<DirFinder>(dirFinders);

            foreach (DirFinder dir in dirSrcs)
            {
                try
                {
                    logDirs.AddRange(dir.getDirs());
                    saveDirInRegistry(dir.getDirectory());
                    break;
                }
                catch (Exception e)
                {
                    log(e.Message);
                }
            }

            if (logDirs.Count() == 0)
            {
                log("No files found to process.");
                setTitle("Unable to find LoL directory.");
            }
            else
            {
                log("Starting processing.");

                //backgroundUploader.RunWorkerAsync(logDirs);

                uploader = new UploadWorker(logDirs, logger);
                workerDelegate = new WorkerDelegate(StartWorker);

                RunWorker();
            }
        }
Ejemplo n.º 23
0
        public static int StartWorker(WorkerDelegate onWork, WorkerFinishedDelegate onFinish = null, WorkerOnProgressDelegate onUpdate = null)
        {
            for (int i = 0; i < m_workerList.Count; i++)
            {
                if (!m_workerList[i].worker.IsBusy)
                {
                    m_workerList[i].onWork     = onWork;
                    m_workerList[i].onProgress = onUpdate;
                    m_workerList[i].onFinish   = onFinish;
                    m_workerList[i].worker.RunWorkerAsync();
                    return(i);
                }
            }
            WorkerClass worker = new WorkerClass();

            worker.onWork     = onWork;
            worker.onProgress = onUpdate;
            worker.onFinish   = onFinish;
            m_workerList.Add(worker);
            worker.worker.RunWorkerAsync();
            return(m_workerList.Count - 1);
        }
Ejemplo n.º 24
0
        internal bool InvokeAsync(T arg, bool isTry)
        {
            lock (this) {
                if (_isBusy)
                {
                    if (isTry)
                    {
                        return(false);
                    }
                    else
                    {
                        throw new InvalidOperationException("Operation is still executing");
                    }
                }
                _isBusy = true;
            }
            _isCancelled = false;
            AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(null);
            WorkerDelegate worker  = new WorkerDelegate(Worker);

            worker.BeginInvoke(arg, asyncOp, null, null);
            return(true);
        }
Ejemplo n.º 25
0
Archivo: ODThread.cs Proyecto: mnisl/OD
		///<summary>Creates a thread that will only run once after Start() is called.</summary>
		public ODThread(WorkerDelegate worker,params object[] parameters) : this(0,worker,parameters) {
		}
        public static void Initialize()
        {
            Version ver = Assembly.GetExecutingAssembly().GetName().Version;
            logger.Info("Moving Pictures (" + ver.Major + "." + ver.Minor + "." + ver.Build + ":" + ver.Revision + ")");
            logger.Info("Plugin Launched");

            // Register Win32 PowerMode Event Handler
            Microsoft.Win32.SystemEvents.PowerModeChanged += new Microsoft.Win32.PowerModeChangedEventHandler(onSystemPowerModeChanged);

            DatabaseMaintenanceManager.MaintenanceProgress += new ProgressDelegate(DatabaseMaintenanceManager_MaintenanceProgress);

            // setup the data structures sotring our list of startup actions
            // we use this setup so we can easily add new tasks without having to
            // tweak any magic numbers for the progress bar / loading screen
            List<WorkerDelegate> initActions = new List<WorkerDelegate>();
            Dictionary<WorkerDelegate, string> actionDescriptions = new Dictionary<WorkerDelegate, string>();
            WorkerDelegate newAction;

            newAction = new WorkerDelegate(initAdditionalSettings);
            actionDescriptions.Add(newAction, "Initializing Path Settings...");
            initActions.Add(newAction);

            newAction = new WorkerDelegate(DatabaseMaintenanceManager.UpdateImportPaths);
            actionDescriptions.Add(newAction, "Updating Import Paths...");
            initActions.Add(newAction);

            // only perform the following tasks (one time) when we are upgrading from a previous version
            if (MovingPicturesCore.GetDBVersionNumber() < ver) {

                // local media
                newAction = new WorkerDelegate(DatabaseMaintenanceManager.PerformFileInformationUpgradeCheck);
                actionDescriptions.Add(newAction, "Performing File Information Upgrade Check...");
                initActions.Add(newAction);

                // movies
                newAction = new WorkerDelegate(DatabaseMaintenanceManager.PerformMovieInformationUpgradeCheck);
                actionDescriptions.Add(newAction, "Performing Movie Information Upgrade Check...");
                initActions.Add(newAction);

                // generic
                newAction = new WorkerDelegate(DatabaseMaintenanceManager.PerformGenericUpgradeChecks);
                actionDescriptions.Add(newAction, "Performing additional upgrade tasks...");
                initActions.Add(newAction);
            }

            newAction = new WorkerDelegate(checkVersionInfo);
            actionDescriptions.Add(newAction, "Initializing Version Information...");
            initActions.Add(newAction);

            newAction = new WorkerDelegate(DatabaseMaintenanceManager.VerifyDataSources);
            actionDescriptions.Add(newAction, "Verifying Data Sources...");
            initActions.Add(newAction);

            newAction = new WorkerDelegate(DataProviderManager.Initialize);
            actionDescriptions.Add(newAction, "Initializing Data Provider Manager...");
            initActions.Add(newAction);

            newAction = new WorkerDelegate(DatabaseMaintenanceManager.VerifyMovieInformation);
            actionDescriptions.Add(newAction, "Updating Movie Information...");
            initActions.Add(newAction);

            newAction = new WorkerDelegate(DatabaseMaintenanceManager.VerifyFilterMenu);
            actionDescriptions.Add(newAction, "Updating Filtering Menu...");
            initActions.Add(newAction);

            // only perform this task when categories are enabled
            if (Settings.CategoriesEnabled) {
                newAction = new WorkerDelegate(DatabaseMaintenanceManager.VerifyCategoryMenu);
                actionDescriptions.Add(newAction, "Updating Categories Menu...");
                initActions.Add(newAction);
            }

            // only perform this task if starting in configuration
            if (!Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location).Equals("mediaportal", StringComparison.InvariantCultureIgnoreCase)) {
                newAction = new WorkerDelegate(DatabaseMaintenanceManager.VerifyMovieManagerFilterMenu);
                actionDescriptions.Add(newAction, "Updating Movie Manager Filter Menu...");
                initActions.Add(newAction);
            }

            newAction = new WorkerDelegate(DeviceManager.StartMonitor);
            actionDescriptions.Add(newAction, "Starting Device Monitor...");
            initActions.Add(newAction);

            // load all the above actions and notify any listeners of our progress
            loadingProgress = 0;
            loadingTotal = initActions.Count;
            foreach (WorkerDelegate currAction in initActions) {
                try {
                    if (InitializeProgress != null) InitializeProgress(actionDescriptions[currAction], (int)(loadingProgress * 100 / loadingTotal));
                    loadingProgressDescription = actionDescriptions[currAction];
                    currAction();
                }
                catch (Exception ex) {
                    // don't log error if the init was aborted on purpose
                    if (ex.GetType() == typeof(ThreadAbortException))
                        throw ex;

                    logger.ErrorException("Error: ", ex);
                }
                finally {
                    loadingProgress++;
                }
            }

            if (InitializeProgress != null) InitializeProgress("Done!", 100);

            // stop listening
            DatabaseMaintenanceManager.MaintenanceProgress -= new ProgressDelegate(DatabaseMaintenanceManager_MaintenanceProgress);

            // Launch background tasks
            startBackgroundTasks();
        }
Ejemplo n.º 27
0
        public static void Initialize()
        {
            Version ver = Assembly.GetExecutingAssembly().GetName().Version;

            logger.Info("Moving Pictures (" + ver.Major + "." + ver.Minor + "." + ver.Build + ":" + ver.Revision + ")");
            logger.Info("Plugin Launched");

            // Register Win32 PowerMode Event Handler
            Microsoft.Win32.SystemEvents.PowerModeChanged += new Microsoft.Win32.PowerModeChangedEventHandler(onSystemPowerModeChanged);

            DatabaseMaintenanceManager.MaintenanceProgress += new ProgressDelegate(DatabaseMaintenanceManager_MaintenanceProgress);

            // setup the data structures sotring our list of startup actions
            // we use this setup so we can easily add new tasks without having to
            // tweak any magic numbers for the progress bar / loading screen
            List <WorkerDelegate> initActions = new List <WorkerDelegate>();
            Dictionary <WorkerDelegate, string> actionDescriptions = new Dictionary <WorkerDelegate, string>();
            WorkerDelegate newAction;

            newAction = new WorkerDelegate(initAdditionalSettings);
            actionDescriptions.Add(newAction, "Initializing Path Settings...");
            initActions.Add(newAction);

            newAction = new WorkerDelegate(DatabaseMaintenanceManager.UpdateImportPaths);
            actionDescriptions.Add(newAction, "Updating Import Paths...");
            initActions.Add(newAction);

            // only perform the following tasks (one time) when we are upgrading from a previous version
            if (MovingPicturesCore.GetDBVersionNumber() < ver)
            {
                // local media
                newAction = new WorkerDelegate(DatabaseMaintenanceManager.PerformFileInformationUpgradeCheck);
                actionDescriptions.Add(newAction, "Performing File Information Upgrade Check...");
                initActions.Add(newAction);

                // movies
                newAction = new WorkerDelegate(DatabaseMaintenanceManager.PerformMovieInformationUpgradeCheck);
                actionDescriptions.Add(newAction, "Performing Movie Information Upgrade Check...");
                initActions.Add(newAction);

                // generic
                newAction = new WorkerDelegate(DatabaseMaintenanceManager.PerformGenericUpgradeChecks);
                actionDescriptions.Add(newAction, "Performing additional upgrade tasks...");
                initActions.Add(newAction);
            }

            newAction = new WorkerDelegate(checkVersionInfo);
            actionDescriptions.Add(newAction, "Initializing Version Information...");
            initActions.Add(newAction);

            newAction = new WorkerDelegate(DatabaseMaintenanceManager.VerifyDataSources);
            actionDescriptions.Add(newAction, "Verifying Data Sources...");
            initActions.Add(newAction);

            newAction = new WorkerDelegate(DataProviderManager.Initialize);
            actionDescriptions.Add(newAction, "Initializing Data Provider Manager...");
            initActions.Add(newAction);

            newAction = new WorkerDelegate(DatabaseMaintenanceManager.VerifyMovieInformation);
            actionDescriptions.Add(newAction, "Updating Movie Information...");
            initActions.Add(newAction);

            newAction = new WorkerDelegate(DatabaseMaintenanceManager.VerifyFilterMenu);
            actionDescriptions.Add(newAction, "Updating Filtering Menu...");
            initActions.Add(newAction);

            // only perform this task when categories are enabled
            if (Settings.CategoriesEnabled)
            {
                newAction = new WorkerDelegate(DatabaseMaintenanceManager.VerifyCategoryMenu);
                actionDescriptions.Add(newAction, "Updating Categories Menu...");
                initActions.Add(newAction);
            }

            // only perform this task if starting in configuration
            if (!Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location).Equals("mediaportal", StringComparison.InvariantCultureIgnoreCase))
            {
                newAction = new WorkerDelegate(DatabaseMaintenanceManager.VerifyMovieManagerFilterMenu);
                actionDescriptions.Add(newAction, "Updating Movie Manager Filter Menu...");
                initActions.Add(newAction);
            }

            newAction = new WorkerDelegate(DeviceManager.StartMonitor);
            actionDescriptions.Add(newAction, "Starting Device Monitor...");
            initActions.Add(newAction);

            // load all the above actions and notify any listeners of our progress
            loadingProgress = 0;
            loadingTotal    = initActions.Count;
            foreach (WorkerDelegate currAction in initActions)
            {
                try {
                    if (InitializeProgress != null)
                    {
                        InitializeProgress(actionDescriptions[currAction], (int)(loadingProgress * 100 / loadingTotal));
                    }
                    loadingProgressDescription = actionDescriptions[currAction];
                    currAction();
                }
                catch (Exception ex) {
                    // don't log error if the init was aborted on purpose
                    if (ex.GetType() == typeof(ThreadAbortException))
                    {
                        throw ex;
                    }

                    logger.ErrorException("Error: ", ex);
                }
                finally {
                    loadingProgress++;
                }
            }

            if (InitializeProgress != null)
            {
                InitializeProgress("Done!", 100);
            }

            // stop listening
            DatabaseMaintenanceManager.MaintenanceProgress -= new ProgressDelegate(DatabaseMaintenanceManager_MaintenanceProgress);

            // Launch background tasks
            startBackgroundTasks();
        }
Ejemplo n.º 28
0
 private void btnGo_Click(object sender, RoutedEventArgs e)
 {
     if (String.IsNullOrEmpty(m_DestFolder) || String.IsNullOrEmpty(m_SourceFolder))
     {
         System.Windows.MessageBox.Show("You need to select destination and source folders");
         return;
     }
     try
     {
         double scale = ParseScale();
         if (scale == 0)
             return;
         if ((m_MaxFiles= Helper.GetValidFilesInDirectory(m_SourceFolder)) == 0)
         {
             System.Windows.MessageBox.Show("No Jpeg files found");
             return;
         }
         fileProgressBar.Maximum = m_MaxFiles;
         asynchDelegate = new WorkerDelegate(Resize);
         IAsyncResult res = asynchDelegate.BeginInvoke(scale,callback,null);
         lblStatus.Content = "Resizing....";
         btnGo.IsEnabled = false;
     }
     catch (Exception ex)
     {
         System.Windows.MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 29
0
        // Should be the first thing that is run whenever the plugin launches, either
        // from the GUI or the Config Screen.
        public static void Initialize(RichTextBox rtb)
        {
            InitLogger(rtb);
            Version ver = Assembly.GetExecutingAssembly().GetName().Version;

            logger.Info(string.Format("mvCentral ({0}.{1}.{2}.{3})", ver.Major, ver.Minor, ver.Build, ver.Revision));
            logger.Info("Plugin launched");


            InitLocalization();
            // Register Win32 PowerMode Event Handler
            Microsoft.Win32.SystemEvents.PowerModeChanged  += new Microsoft.Win32.PowerModeChangedEventHandler(OnSystemPowerModeChanged);
            DatabaseMaintenanceManager.MaintenanceProgress += new ProgressDelegate(DatabaseMaintenanceManager_MaintenanceProgress);


            // setup the data structures sotring our list of startup actions
            // we use this setup so we can easily add new tasks without having to
            // tweak any magic numbers for the progress bar / loading screen
            List <WorkerDelegate> initActions = new List <WorkerDelegate>();
            Dictionary <WorkerDelegate, string> actionDescriptions = new Dictionary <WorkerDelegate, string>();
            WorkerDelegate newAction;

            newAction = new WorkerDelegate(initAdditionalSettings);
            actionDescriptions.Add(newAction, "Initializing Path Settings...");
            initActions.Add(newAction);

            newAction = new WorkerDelegate(DatabaseMaintenanceManager.UpdateImportPaths);
            actionDescriptions.Add(newAction, "Updating Import Paths...");
            initActions.Add(newAction);

            newAction = new WorkerDelegate(CheckVersionInfo);
            actionDescriptions.Add(newAction, "Initializing Version Information...");
            initActions.Add(newAction);

            newAction = new WorkerDelegate(DataProviderManager.Initialize);
            actionDescriptions.Add(newAction, "Initializing Data Provider Manager...");
            initActions.Add(newAction);

            newAction = new WorkerDelegate(DatabaseMaintenanceManager.VerifyMusicVideoInformation);
            actionDescriptions.Add(newAction, "Updating Music Video Information...");
            initActions.Add(newAction);

            newAction = new WorkerDelegate(DeviceManager.StartMonitor);
            actionDescriptions.Add(newAction, "Starting Device Monitor...");
            initActions.Add(newAction);

            // load all the above actions and notify any listeners of our progress
            loadingProgress = 0;
            loadingTotal    = initActions.Count;
            foreach (WorkerDelegate currAction in initActions)
            {
                try
                {
                    if (InitializeProgress != null)
                    {
                        InitializeProgress(actionDescriptions[currAction], (int)(loadingProgress * 100 / loadingTotal));
                    }
                    loadingProgressDescription = actionDescriptions[currAction];
                    currAction();
                }
                catch (Exception ex)
                {
                    // don't log error if the init was aborted on purpose
                    if (ex.GetType() == typeof(ThreadAbortException))
                    {
                        throw ex;
                    }

                    logger.ErrorException("Error: ", ex);
                }
                finally
                {
                    loadingProgress++;
                }
            }

            if (InitializeProgress != null)
            {
                InitializeProgress("Done!", 100);
            }

            // stop listening
            DatabaseMaintenanceManager.MaintenanceProgress -= new ProgressDelegate(DatabaseMaintenanceManager_MaintenanceProgress);

            // Launch background tasks
            mvCentralCore.Settings.AutoRetrieveMediaInfo = true;
            StartBackgroundTasks();
        }
Ejemplo n.º 30
0
        private void reloadDefaultSourcesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            WorkerDelegate worker = new WorkerDelegate(MovingPicturesCore.DataProviderManager.LoadInternalProviders);
            ProgressPopup popup = new ProgressPopup(worker);
            popup.Owner = this.ParentForm;
            popup.ShowDialog();

            reloadList();
        }
Ejemplo n.º 31
0
		///<summary>Add an exit handler that will get fired once the thread loop has exited.
		///Fires in the context of this thread not the context of the calling / creating thread.
		///Make sure to use Invoke or BeginInvoke if you are going to be manipulating UI elements from this handler.</summary>
		public void AddExitHandler(WorkerDelegate exitHandler) {
			_exitHandler+=exitHandler;
		}
Ejemplo n.º 32
0
        // Should be the first thing that is run whenever the plugin launches, either
        // from the GUI or the Config Screen.
        public static void Initialize(RichTextBox rtb)
        {
            InitLogger(rtb);
              Version ver = Assembly.GetExecutingAssembly().GetName().Version;
              logger.Info(string.Format("mvCentral ({0}.{1}.{2}.{3})", ver.Major, ver.Minor, ver.Build, ver.Revision));
              logger.Info("Plugin launched");

              InitLocalization();
              // Register Win32 PowerMode Event Handler
              Microsoft.Win32.SystemEvents.PowerModeChanged += new Microsoft.Win32.PowerModeChangedEventHandler(OnSystemPowerModeChanged);
              DatabaseMaintenanceManager.MaintenanceProgress += new ProgressDelegate(DatabaseMaintenanceManager_MaintenanceProgress);

              // setup the data structures sotring our list of startup actions
              // we use this setup so we can easily add new tasks without having to
              // tweak any magic numbers for the progress bar / loading screen
              List<WorkerDelegate> initActions = new List<WorkerDelegate>();
              Dictionary<WorkerDelegate, string> actionDescriptions = new Dictionary<WorkerDelegate, string>();
              WorkerDelegate newAction;

              newAction = new WorkerDelegate(initAdditionalSettings);
              actionDescriptions.Add(newAction, "Initializing Path Settings...");
              initActions.Add(newAction);

              newAction = new WorkerDelegate(DatabaseMaintenanceManager.UpdateImportPaths);
              actionDescriptions.Add(newAction, "Updating Import Paths...");
              initActions.Add(newAction);

              newAction = new WorkerDelegate(CheckVersionInfo);
              actionDescriptions.Add(newAction, "Initializing Version Information...");
              initActions.Add(newAction);

              newAction = new WorkerDelegate(DataProviderManager.Initialize);
              actionDescriptions.Add(newAction, "Initializing Data Provider Manager...");
              initActions.Add(newAction);

              newAction = new WorkerDelegate(DatabaseMaintenanceManager.VerifyMusicVideoInformation);
              actionDescriptions.Add(newAction, "Updating Music Video Information...");
              initActions.Add(newAction);

              newAction = new WorkerDelegate(DeviceManager.StartMonitor);
              actionDescriptions.Add(newAction, "Starting Device Monitor...");
              initActions.Add(newAction);

              // load all the above actions and notify any listeners of our progress
              loadingProgress = 0;
              loadingTotal = initActions.Count;
              foreach (WorkerDelegate currAction in initActions)
              {
            try
            {
              if (InitializeProgress != null) InitializeProgress(actionDescriptions[currAction], (int)(loadingProgress * 100 / loadingTotal));
              loadingProgressDescription = actionDescriptions[currAction];
              currAction();
            }
            catch (Exception ex)
            {
              // don't log error if the init was aborted on purpose
              if (ex.GetType() == typeof(ThreadAbortException))
            throw ex;

              logger.ErrorException("Error: ", ex);
            }
            finally
            {
              loadingProgress++;
            }
              }

              if (InitializeProgress != null) InitializeProgress("Done!", 100);

              // stop listening
              DatabaseMaintenanceManager.MaintenanceProgress -= new ProgressDelegate(DatabaseMaintenanceManager_MaintenanceProgress);

              // Launch background tasks
              mvCentralCore.Settings.AutoRetrieveMediaInfo = true;
              StartBackgroundTasks();
        }
Ejemplo n.º 33
0
Archivo: ODThread.cs Proyecto: mnisl/OD
		///<summary>Add an exception handler to be alerted of unhandled exceptions in the work delegate.</summary>
		public void AddThreadExitHandler(WorkerDelegate threadExitHandler) {
			_threadExitHandler+=threadExitHandler;
		}
Ejemplo n.º 34
0
		///<summary>Add a delegate that will get called before the main worker delegate starts. If this is a thread that runs repeatedly at an interval,
		///this delegate will only run before the first time the thread is run. It is implied that this is invoked from within the thread context.
		///Make sure to use Invoke or BeginInvoke if you are going to be manipulating UI elements from this handler.</summary>
		public void AddSetupHandler(WorkerDelegate setupHandler) {
			_setupHandler+=setupHandler;
		}
Ejemplo n.º 35
0
		///<summary>Creates a thread that will only run once after Start() is called.</summary>
		public ODThread(WorkerDelegate worker,params object[] parameters) : this(0,worker,parameters) {
		}
Ejemplo n.º 36
0
		///<summary>Creates a thread that will only run once after Start() is called.</summary>
		public ODThread(WorkerDelegate worker) : this(worker,null) {
		}
Ejemplo n.º 37
0
Archivo: ODThread.cs Proyecto: mnisl/OD
		///<summary>Creates a thread that will only run once after Start() is called.</summary>
		public ODThread(WorkerDelegate worker) : this(worker,null) {
		}