Ejemplo n.º 1
0
        static void Main()
        {
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            SystemEvents.SessionEnding += new SessionEndingEventHandler(SessionEnding);

            Mutex mtx = new Mutex(false, "{a6a3ac10-cf4a-48b6-8f53-c949e8db87fb}");       // shared_uuid

            if (mtx.WaitOne(0) == false)                                                  // 多重起動防止
            {
                Mutex mtx_2 = new Mutex(false, "{6aee517a-a9b1-4ec9-81d2-5f3965544641}"); // shared_uuid

                if (mtx_2.WaitOne(0) == false)
                {
                    return;
                }

                Gnd.Ev停止.Set();

                bool mtxOk = mtx.WaitOne(5000);

                mtx_2.ReleaseMutex();
                mtx_2.Close();

                if (mtxOk == false)
                {
                    return;
                }
            }
            LogTools.Clear();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainWin());

            mtx.ReleaseMutex();
            mtx.Close();
        }
Ejemplo n.º 2
0
        private void MainTimer_Tick(object sender, EventArgs e)
        {
            if (this.MT_Enabled == false || this.MT_Busy)
            {
                return;
            }

            this.MT_Busy = true;

            int currPCPos = -1;

            try
            {
                bool rf = false;
                bool wf = false;

                for (int index = 0; index < this.PCList.Count; index++)
                {
                    currPCPos = index;

                    if (0f < this.PCList[index].R.NextValue())
                    {
                        rf = true;
                    }

                    if (0f < this.PCList[index].W.NextValue())
                    {
                        wf = true;
                    }

                    currPCPos = -1;
                    this.PCList[index].ErrorCount = 0;
                }

                bool sf =
                    this.ChainFltr(rf, ref this.Chain_R) ||
                    this.ChainFltr(wf, ref this.Chain_W);

                Icon nextIcon = this.IconIdle;

                if (sf)
                {
                    if (rf)
                    {
                        if (wf)
                        {
                            nextIcon = this.IconBusyRW;
                        }
                        else
                        {
                            nextIcon = this.IconBusyR;
                        }
                    }
                    else                     // (sf && !rf) なら (wf) であるはず。
                    {
                        nextIcon = this.IconBusyW;
                    }
                }
                else
                {
                    if (rf)
                    {
                        if (wf)
                        {
                            nextIcon = this.IconRW;
                        }
                        else
                        {
                            nextIcon = this.IconR;
                        }
                    }
                    else if (wf)
                    {
                        nextIcon = this.IconW;
                    }
                }

                if (this.TaskTrayIcon.Icon != nextIcon)
                {
                    this.TaskTrayIcon.Icon = nextIcon;
                }

                if (this.MT_Count % 6000 == 0)                 // 10分毎に実行
                {
                    GC.Collect();
                }
                if (this.MT_Count % 30 == 0)                 // 3秒毎に実行
                {
                    if (Gnd.Ev停止.WaitOne(0))
                    {
                        this.MT_Enabled = false;
                        this.Close();
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                LogTools.Write(ex);

                if (currPCPos == -1)
                {
                    throw ex;
                }

                this.PCList[currPCPos].ErrorCount++;

                if (this.PCList[currPCPos].ErrorCount < 5)                 // < 0.5[sec]
                {
                    return;
                }

                LogTools.Write("例外が連発しているので " + this.PCList[currPCPos].Drv + " を閉じます。");

                this.PCList[currPCPos].Close();
                this.PCList.RemoveAt(currPCPos);

                this.TaskTrayIcon.Text = this.GetTTIText();
            }
            finally
            {
                this.MT_Busy = false;
                this.MT_Count++;
            }
        }
Ejemplo n.º 3
0
        private void MainWin_Load(object sender, EventArgs e)
        {
            this.IconIdle   = LoadIcon("Idle.ico");
            this.IconR      = LoadIcon("Read.ico");
            this.IconW      = LoadIcon("Write.ico");
            this.IconRW     = LoadIcon("ReadWrite.ico");
            this.IconBusyR  = LoadIcon("BusyRead.ico");
            this.IconBusyW  = LoadIcon("BusyWrite.ico");
            this.IconBusyRW = LoadIcon("BusyReadWrite.ico");

            {
                Exception   firstEx = null;
                List <char> drvs    = new List <char>();

                try
                {
                    string[] args = Environment.GetCommandLineArgs();

                    for (int index = 1; index < args.Length; index++)
                    {
                        foreach (char chr in args[index].ToUpper())
                        {
                            if (StringTools.ALPHA.Contains(chr))
                            {
                                drvs.Add(chr);
                            }
                        }
                    }
                }
                catch
                { }

                if (drvs.Count == 0)
                {
                    foreach (char drv in StringTools.ALPHA)
                    {
                        DriveInfo di = new DriveInfo("" + drv);

                        if (di.DriveType == DriveType.Fixed)
                        {
                            drvs.Add(drv);
                        }
                    }
                }
                StringTools.ToUnique(drvs);

                foreach (char drv in drvs)
                {
                    try
                    {
                        PerformanceCounter r = new PerformanceCounter("LogicalDisk", "Disk Read Bytes/sec", drv + ":");
                        PerformanceCounter w = new PerformanceCounter("LogicalDisk", "Disk Write Bytes/sec", drv + ":");

                        PCInfo info = new PCInfo();

                        info.Drv = drv;
                        info.R   = r;
                        info.W   = w;

                        this.PCList.Add(info);
                    }
                    catch (Exception ex)
                    {
                        LogTools.Write(ex);

                        if (firstEx == null)
                        {
                            firstEx = ex;
                        }
                    }
                }
                if (this.PCList.Count == 0)
                {
                    string sDrv = new string(drvs.ToArray());

                    MessageBox.Show(
                        "パフォーマンスカウンタのオープンに失敗しました。\ndrv: " + sDrv + "\nex: " + firstEx,
                        "AccessLamp Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                        );
                }
            }

            string ttiText = this.GetTTIText();

            LogTools.Write(ttiText);

            this.TaskTrayIcon.Icon = this.IconIdle;
            this.TaskTrayIcon.Text = ttiText;

            GC.Collect();
        }
Ejemplo n.º 4
0
 private void MainWin_FormClosing(object sender, FormClosingEventArgs e)
 {
     LogTools.Clear();
 }