|
-
Jun 28th, 2007, 10:01 PM
#1
Thread Starter
Fanatic Member
help with progressbar and Thread
hi guys! i have a code below that supposedly, Set e.Cancel to true, set the LblProgressBar (a ToolStripStatusLabel) Text Property to "Performing Backup" and Visible property to true, set the pBar(a ToolStripProgressBar) Visible property to true and call the function FuncPeformBackup using Thread after the FuncPerformBackup is finished set the e.Cancel to false, for it to close the form, But it doest not work the way I expected the LblProgressBar and pBar does not show up. I inserted 200,000 rows in one of the tables in the database for the backup to take a while and to check if the label and the progress bar will show up..but i have no luck. I just want to have a progress bar to let the user know that the application is performing backup job in background. Any suggestion guys on how can i solve this problem..Thanks!
Code:
private void RCPSIndex_FormClosing(object sender, FormClosingEventArgs e)
{
if (DBBackupRecovery.dbEnableBackup && DBBackupRecovery.dbBackupEverySysClose)
{
e.Cancel = true;
LblProgressBar.Text = "Performing Backup";
LblProgressBar.Visible = true;
pBar.Visible = true;
Thread t = new Thread(new ThreadStart(FuncPeformBackup));
t.Start();
Thread.Sleep(100);
t.IsBackground = true;
t.Join();
e.Cancel = false;
}
}
-
Jun 29th, 2007, 04:49 AM
#2
Re: help with progressbar and Thread
try using the Backgroundworker component. It can report progress to a progressbar while doing the work
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jul 2nd, 2007, 03:35 AM
#3
Thread Starter
Fanatic Member
Re: help with progressbar and Thread
Actually, I've tried that prior to creating this thread but got no luck.
Code:
private void RCPSIndex_FormClosing(object sender, FormClosingEventArgs e)
{
if (DBBackupRecovery.dbEnableBackup && DBBackupRecovery.dbBackupEverySysClose)
{
e.Cancel = true;
LblProgressBar.Text = "Performing Backup";
LblProgressBar.Visible = true;
pBar.Visible = true;
BackupBackgrndWorker.RunWorkerAsync();
e.Cancel = false;
//I know there is a problem here, It will exit without checking if BackupBackgrndWorker
//is Completed
}
}
private void BackupBackgrndWorker_DoWork(object sender, DoWorkEventArgs e)
{
FuncPeformBackup();
}
private void BackupBackgrndWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
LblProgressBar.Text = "Backup Completed";
LblProgressBar.Visible = false;
pBar.Visible = false;
BackupBackgrndWorker.Dispose();
}
public void FuncPeformBackup()
{
string BackFilePath = CommonFunctions.GenerateBackupFileName();
bool backup = CommonFunctions.BackUpDB(DBBackupRecovery.dbServer, DBBackupRecovery.dbName, DBBackupRecovery.dbUserName,
DBBackupRecovery.dbPassword, BackFilePath, DBBackupRecovery.dbUseWindowAuthentication);
}
-
Jul 2nd, 2007, 07:28 AM
#4
Re: help with progressbar and Thread
RunWorkerAsync() means start running on another thread so the maching initializes that thread and gets back to where it left which is "e.Cancel = false;" so it exits the application
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jul 2nd, 2007, 08:00 AM
#5
Hyperactive Member
Re: help with progressbar and Thread
call this to update your progressbar wouldn't be a bad idea either.
vb Code:
void bw_ProgressChanged (object sender,
ProgressChangedEventArgs e) { }
http://www.albahari.com/threading/pa...ckgroundWorker
-
Jul 2nd, 2007, 08:21 AM
#6
Re: help with progressbar and Thread
 Originally Posted by superbovine
Actually there is a method called ReportProgress in the BackgroundWorker Class to do that
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jul 2nd, 2007, 09:41 PM
#7
Hyperactive Member
Re: help with progressbar and Thread
 Originally Posted by ComputerJy
Actually there is a method called ReportProgress in the BackgroundWorker Class to do that
you got the idea:P
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|