示例#1
0
        private void load(object s, EventArgs e)
        {
            ion2.loadSettings(); // automatically initialize settings class
            // then loads settings to dictionary object

            // -------- initialize context menu
            listView1.ContextMenu = new ContextMenu()
            {
                Name = "taskListMenu"
            };

            MenuItem ls1 = new MenuItem("Remove Task");
            MenuItem ls2 = new MenuItem("Start Task");
            MenuItem ls3 = new MenuItem("Pause Task");

            ls1.Click += (ee, bb) => {
                if (listView1.SelectedItems.Count < 1)
                {
                    return;
                }
                removeTask((string)listView1.SelectedItems[0].Tag);
            };
            ls2.Click += (ci, eo) => {
                if (listView1.SelectedItems.Count < 1)
                {
                    return;
                }
                startTask((string)listView1.SelectedItems[0].Tag);
            };
            ls3.Click += (wi, ck) => {
                if (listView1.SelectedItems.Count < 1)
                {
                    return;
                }
                stopTask((string)listView1.SelectedItems[0].Tag);
            };
            listView1.ContextMenu.MenuItems.Add(ls1);
            listView1.ContextMenu.MenuItems.Add(ls2);
            listView1.ContextMenu.MenuItems.Add(ls3);
            listView1.ContextMenu.Popup += (df, vn) => {
                foreach (MenuItem lt in listView1.ContextMenu.MenuItems)
                {
                    lt.Enabled = false;
                }
                if (listView1.SelectedItems.Count < 1)
                {
                    return;
                }
                listView1.ContextMenu.MenuItems[0].Enabled = true;
                if (taskIsActive((string)listView1.SelectedItems[0].Tag))
                {
                    ls3.Enabled = true;
                }
                else
                {
                    ls2.Enabled = true;
                }
            };

            // -------------
            FormClosing += (ee, vv) => {
                foreach (Spammer spc in Q.Values)
                {
                    spc.Stop();
                }
                ion2.saveSettings();
            };

            // -------------

            Q = new Dictionary <string, Spammer>();


            // -------------- timer 1
            System.Windows.Forms.Timer tt = new System.Windows.Forms.Timer();
            tt.Interval = 350;
            tt.Tick    += (df, gd) => {
                counterLbl.Text = (string)"Queue: " + Q.Count;
            };
            tt.Start();
            // -------------- status timer
            System.Windows.Forms.Timer ty = new System.Windows.Forms.Timer();
            ty.Interval = 1000;
            ty.Tick    += (em, cl) => {
                // this is a very crude, ineffective way of doing this, but
                // I'm lazy and it works.
                foreach (ListViewItem ii in listView1.Items)
                {
                    Spammer spc = Q[(string)ii.Tag];
                    ii.SubItems[1].Text = spc.Status();
                }
            };
            ty.Start();
        }
        private void load(object s, EventArgs e)
        {
            u = new ion.User();
            ion2.loadSettings(); // automatically initialize settings class
            // then loads settings to dictionary object


            // --------
            listView1.ContextMenu = new ContextMenu()
            {
                Name = "taskListMenu"
            };

            MenuItem ls1 = new MenuItem("Remove Task");
            MenuItem ls2 = new MenuItem("Start Task");

            ls1.Click += (ee, bb) => {
                if (listView1.SelectedItems.Count < 1)
                {
                    return;
                }
                removeTask((string)listView1.SelectedItems[0].Tag);
            };
            ls2.Click += (ci, eo) => {
                if (listView1.SelectedItems.Count < 1)
                {
                    return;
                }
                startTask((string)listView1.SelectedItems[0].Tag);
            };
            listView1.ContextMenu.MenuItems.Add(ls1);
            listView1.ContextMenu.MenuItems.Add(ls2);
            listView1.ContextMenu.Popup += (df, vn) => {
                if (listView1.SelectedItems.Count < 1)
                {
                    return;
                }
            };

            // -------------
            FormClosing += (ee, vv) => {
                foreach (Spammer spc in Q.Values)
                {
                    spc.Stop();
                }
                ion2.saveSettings();
            };

            // -------------

            Q = new Dictionary <string, Spammer>();


            // -------------- timer 1
            System.Windows.Forms.Timer tt = new System.Windows.Forms.Timer();
            tt.Interval = 350;
            tt.Tick    += (df, gd) => {
                counterLbl.Text = (string)"Queue: " + Q.Count;
            };
            tt.Start();
            // -------------- status timer
            System.Windows.Forms.Timer ty = new System.Windows.Forms.Timer();
            ty.Interval = 1000;
            ty.Tick    += (em, cl) => {
                foreach (ListViewItem ii in listView1.Items)
                {
                    Spammer spc = Q[(string)ii.Tag];
                    ii.SubItems[1].Text = spc.Status();
                }
            };
            ty.Start();
        }