备份数据库的时候想显示一个gif动画,但是那个动画就是不动。using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Threading;namespace SqlTool
{
public partial class BakData : Form
{
public BakData()
{
InitializeComponent();
}
private Thread ths;
private void button3_Click(object sender, EventArgs e)
{
saveFileDialog1.Filter = "*.bak|*.bak";
saveFileDialog1.ShowDialog();
this.textBox1.Text = saveFileDialog1.FileName;
} private void button2_Click(object sender, EventArgs e)
{
this.Close();
} private void BakData_Load(object sender, EventArgs e)
{
this.pictureBox1.Visible = false;
this.label3.Text = ChangeLogin.getDataName;
} private void button1_Click(object sender, EventArgs e)
{
this.button1.Enabled = false;
Thread showPic = new Thread(new ThreadStart(threadPict));
Thread backThread = new Thread(new ThreadStart(threadchange));
backThread.IsBackground = true;
showPic.IsBackground = true;
backThread.Start();
showPic.Start();
} private void showPict()//显示图片
{
this.pictureBox1.Visible = true;
}
private void backQuery()//执行备份
{
Application.DoEvents();
SqlConnection con = new SqlConnection(LoginSql.conLocalhost);
try
{
con.Open();
SqlCommand com = new SqlCommand("BACKUP DATABASE [" + label3.Text + "] TO DISK = N'" + textBox1.Text + "' WITH NOFORMAT, NOINIT, NAME = N'" + label3.Text + "-完整 数据库 备份', SKIP, NOREWIND, NOUNLOAD, STATS = 10", con);
com.ExecuteNonQuery();
this.Close();
con.Close();
}
catch(Exception ex)
{
MessageBox.Show("不能备份数据库" + label3.Text+ex.ToString(), "停止", MessageBoxButtons.OK, MessageBoxIcon.Stop);
con.Close();
return;
}
MessageBox.Show(label3.Text + "数据备份完成", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void threadchange()//通过委托处理
{
MethodInvoker isn = new MethodInvoker(backQuery );
this.BeginInvoke(isn);
}
private void threadPict()
{
MethodInvoker isn = new MethodInvoker( showPict);
this.BeginInvoke (isn);
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Threading;namespace SqlTool
{
public partial class BakData : Form
{
public BakData()
{
InitializeComponent();
}
private Thread ths;
private void button3_Click(object sender, EventArgs e)
{
saveFileDialog1.Filter = "*.bak|*.bak";
saveFileDialog1.ShowDialog();
this.textBox1.Text = saveFileDialog1.FileName;
} private void button2_Click(object sender, EventArgs e)
{
this.Close();
} private void BakData_Load(object sender, EventArgs e)
{
this.pictureBox1.Visible = false;
this.label3.Text = ChangeLogin.getDataName;
} private void button1_Click(object sender, EventArgs e)
{
this.button1.Enabled = false;
Thread showPic = new Thread(new ThreadStart(threadPict));
Thread backThread = new Thread(new ThreadStart(threadchange));
backThread.IsBackground = true;
showPic.IsBackground = true;
backThread.Start();
showPic.Start();
} private void showPict()//显示图片
{
this.pictureBox1.Visible = true;
}
private void backQuery()//执行备份
{
Application.DoEvents();
SqlConnection con = new SqlConnection(LoginSql.conLocalhost);
try
{
con.Open();
SqlCommand com = new SqlCommand("BACKUP DATABASE [" + label3.Text + "] TO DISK = N'" + textBox1.Text + "' WITH NOFORMAT, NOINIT, NAME = N'" + label3.Text + "-完整 数据库 备份', SKIP, NOREWIND, NOUNLOAD, STATS = 10", con);
com.ExecuteNonQuery();
this.Close();
con.Close();
}
catch(Exception ex)
{
MessageBox.Show("不能备份数据库" + label3.Text+ex.ToString(), "停止", MessageBoxButtons.OK, MessageBoxIcon.Stop);
con.Close();
return;
}
MessageBox.Show(label3.Text + "数据备份完成", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void threadchange()//通过委托处理
{
MethodInvoker isn = new MethodInvoker(backQuery );
this.BeginInvoke(isn);
}
private void threadPict()
{
MethodInvoker isn = new MethodInvoker( showPict);
this.BeginInvoke (isn);
}
}
}
private void threadPict()
{
MethodInvoker isn = new MethodInvoker( showPict);
this.BeginInvoke (isn);
}
是这里的问题吗?