private void tmr_Tick(object sender, EventArgs e) { try { tmr.Stop(); DataTable dt = new DataTable(); if (ownerID != null && ownerID != 0) { tu = obj.chkActiveTimer(ownerID); dt = tu.TimerUtilityDt; } tmr.Start(); if (dt.Rows.Count > 0) { if (flag == 0 && !_timerRunning) { if (dt.Rows[0]["ON_TIMER"].ToString() == "Y") { _startTime = DateTime.Now; _totalElapsedTime = _currentElapsedTime; _currentElapsedTime = TimeSpan.Zero; if (linkUT.Text == "Project Task") { changeUTType(); } flag = flag + 1; comboBox1.Text = obj.getProName(dt.Rows[0]["project_ref_id"].ToString()); // comboBox1_SelectedIndexChanged(this, EventArgs.Empty); cbTaskList.ValueMember = "REF_ID"; cbTaskList.DisplayMember = "SCOPE_DETAILS"; //cbTaskList.DataSource = dt; cbTaskList.SelectedValue = dt.Rows[0]["ref_id"].ToString(); comboBox1.Enabled = false; cbTaskList.Enabled = false; linkUT.Enabled = false; _timer.Start(); btnTimer.Text = "STOP"; this.btnTimer.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnTimer.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent; btnTimer.BackgroundImage = ETimerUtility.Properties.Resources.stop_btn; _currentElapsedTimeDisplay.Visible = true; } } } else { flag = 0; linkUT.Enabled = true; comboBox1.Enabled = true; cbTaskList.Enabled = true; _timer.Stop(); _totalElapsedTime = TimeSpan.Zero; _currentElapsedTime = TimeSpan.Zero; string taskID = cbTaskList.SelectedValue.ToString(); if (taskID != "0" && taskID != "-1" && taskID != "-2" && projectID != "0" && projectID != "" && projectID != null) { lblAllocHrs.Visible = lblUsedHrs.Visible = true; tu = obj.CalculateHrs(projectID, taskID, ownerID); dt = tu.TimerUtilityDt; if (dt.Rows.Count > 0) { lblAllocHrs.Text = lblUsedHrs.Text = ""; lblAllocHrs.Text = "Allocated Hrs" + " : " + dt.Rows[0]["allocatedhrs"].ToString(); lblUsedHrs.Text = "Used Hrs" + " : " + dt.Rows[0]["usedhrs"].ToString(); } } btnTimer.BackgroundImage = ETimerUtility.Properties.Resources.start_btn; btnTimer.Text = "START"; this.btnTimer.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnTimer.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent; _currentElapsedTimeDisplay.Text = "00"; _lblCurrentElapsedTimeMin.Text = "00"; _lblCurrentDisplayTimeSec.Text = "00"; } dt.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
How to resolve null refernce exception when calling a method tu = obj.chkActiveTimer(ownerID); throwing exception.It works for some time and then throws exception
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)