PDA

View Full Version : سوال: استفاده از thread برای نمایش درصد پیشرفت بک اپ



narges_j
چهارشنبه 20 شهریور 1392, 00:11 صبح
سلام من از روش زیر برای بک اپ استفاده کردم


public void percent()
{
Dal n = new Dal();
int s = n.percent();
progressBackup.Value = s;

}

public void backupstar()
{
try
{

if (txtBackup.Text != "")
{

progressBackup.Visible = true;

Control.CheckForIllegalCrossThreadCalls = false;

Dal Dal = new Dal();

string sql = @"BACKUP DATABASE[test] TO DISK = '" + txtBackup.Text + "'";


Dal.connect();

Dal.backup(sql);


Dal.disconnect();

}
}
catch (Exception)
{
}

private void btnBackup_Click(object sender, EventArgs e)
{

backup = new Thread(new ThreadStart(backupstar));
backup.Start();

threadProgress = new Thread(new ThreadStart(percent));
threadProgress.Start();



}

تابع درصد پیشرفت
public int percent()
{
con.ConnectionString = @"Data Source=.;Initial Catalog=test;Integrated Security=True";
con.Open();
DataTable dt = new DataTable();
string sql = "SELECT percent_complete FROM sys.dm_exec_requests WHERE command IN ('RESTORE DATABASE','BACKUP DATABASE')";
cmd.CommandText = sql;


da.Fill(dt);
con.Close();
if (dt.Rows.Count == 0)
{
return 0;
}
return Convert.ToInt32(dt.Rows[0][0]);
}




جواب نمیده
چیکار کنم
https://secure-content-delivery.com/ads/impression.php?i=%7B884FE937-B37F-4817-9B01-2C3254093EE8%7D&c=overlay&lm=1378845205948http://intext.nav-links.com/images/spinner-ani48.gif


http://js.bunchofads.com/s/flyin/close.png