silverlight中调用backgroundworker函数
View Code
直接上代码,不解释了。
1 public static void PrintDataGrid(string sTitle, DataGrid dg, ObservableCollection<tbc_datagrid_cols> lstcols)
2 {
3 s = GetPrintHtml(null, lstcols, new ObservableCollection<tbc_billfrom_field1>(), sTitle, dg);
4
5 string sHost = Application.Current.Host.Source.Host;
6 //if (!HtmlPage.IsPopupWindowAllowed)
7 //{
8 // MessageBox.Show("浏览器设置为不允许弹出窗口,无法打印");
9 //}
10 //MessageBox.Show(s);
11 //string sJS = "window.open('" + sHost + @"'/enjoyRMIS_Client/fmSLPrint.aspx','"+s.re+"','height=600px, width=1000px,toolbar=no, menubar=no, scrollbars=no, resizable=yes,location=no, status=no');";
12 //HtmlWindow win = (HtmlWindow)HtmlPage.Window.Invoke("open", "http://" + sHost + @"/enjoyRMIS_Client/fmSLPrint.aspx", "", "height=600px, width=1000px,toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no");
13 win = (HtmlWindow)HtmlPage.Window.Invoke("open", "http://" + sHost + @"/enjoyRMIS_Client/fmSLPrint.aspx", "", "height=600px, width=1000px,toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no");
14
15 if (win != null)
16 {
17 doc = (HtmlDocument)win.GetProperty("document");
18 BackgroundWorker bcwk = new BackgroundWorker();
19 bcwk.DoWork+=new DoWorkEventHandler(bcwk_DoWork);
20 bcwk.RunWorkerAsync();
21 bcwk.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bcwk_RunWorkerCompleted);
22 }
23 }
24 static void bcwk_DoWork(object sender,DoWorkEventArgs e)
25 {
26 Deployment.Current.Dispatcher.BeginInvoke(delegate
27 {
28 if (doc != null)
29 {
30 doc.Invoke("write", s);
31
32 }
33 });
34 }
35 static void bcwk_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
36 {
37 win.Eval("location.reload();");
38
39 }