Exemplo n.º 1
0
        void DoWork()
        {
            string[] array     = new string[2];
            DMLTools dmlinsert = new DMLTools();

            while (IsCancelled == false)
            {
                int threadid = Thread.CurrentThread.ManagedThreadId;
                array = dmlinsert.InsertINTOAccessTable(threadid.ToString());

                if (_shutdownEvent.WaitOne(0))
                {
                    break;
                }

                Random rnd2    = new Random();
                int    sleepms = rnd2.Next(1500, 2001);
                Thread.Sleep(sleepms);
                if (IsHandleCreated)
                {
                    listViewThreadCtrl.Invoke(new UpdatelistView(UpdateUI), array[0], array[1]);
                }
                else
                {
                    Stop();
                }
#if DEBUG
                Debug.WriteLine("Thread Id=" + threadid + "is running." + array[0] + ":" + array[1]);
#endif
            }
        }
Exemplo n.º 2
0
        //void DeleteFromAccessTable()
        //{
        //    using (OleDbConnection conn = new OleDbConnection(connectionString))
        //    {
        //        string deleteqerystr = "";
        //        deleteqerystr = "DELETE FROM ThreadsLog WHERE id IN (3,4,5,7);";
        //        using (OleDbCommand cmd = new OleDbCommand(deleteqerystr, conn))
        //        {
        //            conn.Open();
        //            cmd.ExecuteNonQuery();
        //            //conn.Close();
        //        }
        //    }
        //}

        private void btnStart_Click(object sender, EventArgs e)
        {
            int counter = 0;

            IsCancelled = false;

            if ((!txtbxThreadCnt.Text.All(c => Char.IsNumber(c))) || (txtbxThreadCnt.Text == ""))
            {
                MessageBox.Show("Error on 'Threads count' field: selected value is NaN!", "Application error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if ((Int32.Parse(txtbxThreadCnt.Text) > 1) && (Int32.Parse(txtbxThreadCnt.Text) < 16))
                {
                    listViewThreadCtrl.Items.Clear();
                    DMLTools dmltool = new DMLTools();

                    List <ThreadData> tdlist = dmltool.ThreadListTable();
                    foreach (var item in tdlist)
                    {
                        ListViewItem lvitem = new ListViewItem((++counter).ToString());
                        lvitem.SubItems.Add(item.threadId.ToString());
                        lvitem.SubItems.Add(item.threadData.ToString());
                        listViewThreadCtrl.Items.Add(lvitem);
                    }
                    for (int i = 0; i < Int32.Parse(txtbxThreadCnt.Text); i++)
                    {
                        Start((i + 1).ToString());
                    }

                    btnStop.Enabled  = true;
                    btnStart.Enabled = false;
                }
                else
                {
                    MessageBox.Show("Error on 'Threads count' field: Wrong number. Valid value range is [2..15]!", "Application error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }