日期:2014-05-18  浏览次数:20980 次

winform中备份数据的时候,怎么显示进度条
public bool BackUpDB()
  {
  SQLDMO.SQLServer sr = new SQLDMO.SQLServerClass();
  SQLDMO.Backup bak = new SQLDMO.Backup();
  try
  {
  string serverName = "localhost";
  string UserName = "sa";
  string Password = "123";
  string FilePathBack = @"G:\\DataBase\BackUpDB\";
  string strDbName = "FMSys";
  sr.LoginSecure = false;
  sr.Connect(serverName, UserName, Password);
  bak.Action = 0;
  bak.Initialize = true; 
  SQLDMO.BackupSink_PercentCompleteEventHandler pceh = new SQLDMO.BackupSink_PercentCompleteEventHandler(Step);
  bak.PercentComplete += pceh ;
  bak.Files = FilePathBack + strDbName +".bak";
  bak.Database = strDbName;
  bak.BackupSetName = strDbName;
  bak.BackupSetDescription = "数据库备份";
  bak.SQLBackup(sr);
  return true;
  }
  catch (Exception ex)
  {
  throw (new Exception("备份数据库失败" + ex.Message));
  }
  }
  private void Step(string message, int percent)
  {
  progressBar1.Value = percent;
  Application.DoEvents();
  }
我用的vs2010和sql2008,这样写,怎么不显示进度条,谢谢

------解决方案--------------------
看看是否触发了 Step ,如果触发了,参数是什么值
------解决方案--------------------
如果要用到进度条显示的话,我估计需要用到多线程吧,要不然可能会使程序卡在备份那一步,而无法进入进度条这一步,浅见不知道说的对不对
------解决方案--------------------
以前做个一个进度条,当时出现了界面假死的现象,后来利用委托另起一个线程解决的