private void btnHang_Click_1(object sender, EventArgs e) { int minute = DateTime.Now.Minute; int hour = DateTime.Now.Hour; int callID = int.Parse(txtCallID.Text); string clientID = txtSearch.Text; string clientName = txtClientName.Text; string surname = txtSurname.Text; string phoneNumber = txtPhoneNumber.Text; DateTime calldate = DateTime.Parse(dtpCallDate.Text); string callduration = lblDuration.Text; string callTime = string.Format(hour + ":" + minute); string reason = txtCallReason.Text; if (Counting) { Counting = false;//this will stop the datetime thread } else { try { Counting = true; if (!DurationTimer.IsAlive) { DurationTimer = new Thread(() => { displayTime = DateTime.Parse(("00:00:00").ToString()); DateTime now = DateTime.Now; while (Counting) { displayTime = (displayTime.AddSeconds(1)); Hangup(); Thread.Sleep(1000); } }); DurationTimer.Start(); } } catch (Exception ee) { MessageBox.Show(ee.Message); } } newCalls.InsertCalls(callID, clientID, clientName, surname, phoneNumber, calldate, callTime, callduration, reason); MessageBox.Show("Call Recorded"); txtCallID.Clear(); txtCallReason.Clear(); txtSearch.Clear(); txtPhoneNumber.Clear(); txtSurname.Clear(); txtClientName.Clear(); txtCallID.Clear(); Random rand = new Random(); int callId = rand.Next(0000, 999999); txtCallID.Text = callId.ToString(); }