做了个程序点击打印预览后需要很长时间才反应过来,并且打印按钮也卡住了。其实不止这一点,很多地方会使程序未响应。。。除了用BackGroundWorks之外还可以用委托调用一个正在缓冲窗体。
点击打印预览的代码:
代码
1 protected override void DataPrintView()
2 {
3 Print p = new Print();
4
5 p.PrintMethod(() =>
6 {
7 if (Pager.getAllData == null)
8 { MessageBox.Show("不存在任何数据!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; }
9 if (base.RdlcPath == null)
10 {
11 base.RdlcPath = Application.StartupPath + "\\StandardReports\\" + this.Text + ".rdlc";
12 }
13 base.Repdatasource = "hitestDataSet";
14 base.Repdatavalue = Pager.getAllData;
15 base.C1F = C1F1;
16 base.DataPrintView();
17 });
18 }
2 {
3 Print p = new Print();
4
5 p.PrintMethod(() =>
6 {
7 if (Pager.getAllData == null)
8 { MessageBox.Show("不存在任何数据!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; }
9 if (base.RdlcPath == null)
10 {
11 base.RdlcPath = Application.StartupPath + "\\StandardReports\\" + this.Text + ".rdlc";
12 }
13 base.Repdatasource = "hitestDataSet";
14 base.Repdatavalue = Pager.getAllData;
15 base.C1F = C1F1;
16 base.DataPrintView();
17 });
18 }
Print p = new Print();
是处理的此方法的一个类。
代码如下:
代码
1 public class Print
2 {
3 public delegate void Action();
4 FrmWating Frm = new FrmWating();
5 public void PrintMethod(Action del)
6 {
7 AsyncCallback acb = new AsyncCallback(CallBackMethod);
8
9 del.BeginInvoke(acb, del);
10 Frm.ShowDialog();
11 }
12
13 private void CallBackMethod(IAsyncResult ar)
14 {
15 Action del = (Action)ar.AsyncState;
16 if (Frm.IsHandleCreated)
17 Frm.BeginInvoke(new Action(() => { Frm.Close(); }));
18 del.EndInvoke(ar);
19 }
20 }
2 {
3 public delegate void Action();
4 FrmWating Frm = new FrmWating();
5 public void PrintMethod(Action del)
6 {
7 AsyncCallback acb = new AsyncCallback(CallBackMethod);
8
9 del.BeginInvoke(acb, del);
10 Frm.ShowDialog();
11 }
12
13 private void CallBackMethod(IAsyncResult ar)
14 {
15 Action del = (Action)ar.AsyncState;
16 if (Frm.IsHandleCreated)
17 Frm.BeginInvoke(new Action(() => { Frm.Close(); }));
18 del.EndInvoke(ar);
19 }
20 }