Beispiel #1
0
        void _checkApplications_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (caBusy)
            {
                return;
            }
            caBusy = true;

            var prcsList = Process.GetProcesses();

            // Do it for the manual selected sim
            if (!AutoMode)
            {
                var app = this.Active;
                if (app == null)
                {
                    caBusy = false;
                    return;
                }
                // Search for the process
                bool wasRuning = app.Running;
                app.Running       = prcsList.Any(x => x.ProcessName.ToLower() == app.Application.ToLower());
                app.RunEvent      = app.Running != wasRuning;
                app.ActiveProcess = prcsList.FirstOrDefault(x => x.ProcessName.ToLower() == app.Application.ToLower());

                if (app.RunEvent)
                {
                    if (app.Running)
                    {
                        app.EvtStart();
                        if (AppActive != null)
                        {
                            AppActive(this, new EventArgs());
                        }
                        else
                        {
                            app.EvtStop();
                            if (AppInactive != null)
                            {
                                AppInactive(this, new EventArgs());
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (var app in miners.Where(x => !x.SelectManually))
                {
                    bool wasRuning = app.Running;
                    app.Running       = prcsList.Any(x => x.ProcessName.ToLower() == app.Application.ToLower());
                    app.RunEvent      = app.Running != wasRuning;
                    app.ActiveProcess = prcsList.FirstOrDefault(x => x.ProcessName.ToLower() == app.Application.ToLower());

                    if (app.RunEvent && app.IsActive && app.Running == false)
                    {
                        app.EvtStop();
                        if (AppInactive != null)
                        {
                            AppInactive(this, new EventArgs());
                        }
                    }

                    app.IsActive = false;
                }
                if (miners.Where(x => !x.SelectManually).Any(x => x.Running))
                {
                    // Conflict?
                    Active = miners.Count(x => x.Running) != 1 ? null : miners.Where(x => !x.SelectManually).FirstOrDefault(x => x.Running);
                    if (Active != null)
                    {
                        Active.IsActive = true;

                        // TODO: This seems buggy way..
                        if (Active.RunEvent)
                        {
                            Active.EvtStart();
                            if (AppActive != null)
                            {
                                AppActive(this, new EventArgs());
                            }
                        }
                    }
                }
            }
            caBusy = false;
        }