I have a silly problem but i am stuck. I am executing a stored procedure form my code procedure takes time so for this I am displaying a progress bar, which shows the progre
I studied Background worker and i do it this way I put execution of my procedure on another thread and progress bar in GUI thread
BackgroundWorker bg = new BackgroundWorker();
Boolean stopwork = true;
Private void btnYes_Click(object sender, EventArgs e)
{
if (DialogResult.Yes == MessageBox.Show(clsGlobalObjectRefrances.OMessageString.SureWant2UpdateMarks, "", MessageBoxButtons.YesNo))
{
try
{
bg.DoWork += bg_DoWork;
bg.RunWorkerCompleted += bg_RunWorkerCompleted;
bg.RunWorkerAsync();
pgbUpdateMarks.Maximum = 60;
Stopwatch st = new Stopwatch();
st.Start();
while(stopwork)
{
pgbUpdateMarks.Value = st.Elapsed.Seconds;
}
pgbUpdateMarks.Value = 0;
MessageBox.Show("Executed sucessfully");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Where DoWork is
void bg_DoWork(object sender, DoWorkEventArgs e)
{
dbDataEntities db = new dbDataEntities();
string myquery = "DECLARE @return_value int EXEC @return_value = [dbo].[ssspUpdateMarksOfStudent] SELECT 'Return Value' = @return_value";
db.Database.ExecuteSqlCommand("myquery");
stopwork = false;
}