Пример #1
0
        /// <summary>
        /// The Thread for generating NM graph.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void nm_DoWork(object sender, DoWorkEventArgs e)
        {
            nm_TestObject data = e.Argument as nm_TestObject;

            data.start = DateTime.Now;
            GraphNM graf = new GraphNM();

            graf.Generate(data.n, data.m);

            data.graf = graf;

            e.Result = data;
        }
Пример #2
0
        /// <summary>
        /// This event is called when the BackgroundWorker component(Thread) process is completed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void nm_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            nm_TestObject data = e.Result as nm_TestObject;

            DateTime date     = DateTime.Now;
            TimeSpan timeDiff = date - data.start;

            listView1.Items[data.index].SubItems[2].Text = "Hotovo.";
            listView1.Items[data.index].SubItems[1].Text = date.ToString("dd. MM. yyyy hh:mm:ss") + " (" + timeDiff.TotalSeconds.ToString("0.00") + "s)";

            GraphItem item = new GraphItem();

            item.graph = (Graph)data.graf;
            item.type  = GraphItem.NM;

            graphs.Add(data.index, item);
        }
Пример #3
0
        /// <summary>
        /// Click event for Generate NM graph button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void nMGrafToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            FormNMSetup fnm = new FormNMSetup();

            //Opens a dialog to set NP graph parameters. When the DialogResult is OK, then it starts a new thread for generating the graph.
            if (fnm.ShowDialog() == DialogResult.OK)
            {
                ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] {
                    "Graf NM (n=" + fnm.n.ToString() + ", m=" + fnm.m.ToString() + ")",
                    "",
                    "Generuje sa..."
                }, -1);
                listView1.Items.Add(listViewItem1);
                BackgroundWorker t    = new BackgroundWorker();
                nm_TestObject    data = new nm_TestObject();
                data.index            = listView1.Items.Count - 1;
                data.n                = fnm.n;
                data.m                = fnm.m;
                t.DoWork             += nm_DoWork;
                t.RunWorkerCompleted += nm_RunWorkerCompleted;
                t.RunWorkerAsync(data);
            }
        }