C# 中需要延时,该怎么做.求解

C#在操作word时,将RichTextBox内容粘贴到word时失败,昨天经网友提醒,发现是延时的.
于是今天在copy()之后,延时几秒中以达到效果.但怎么也不成功.求教

 string strDirectory = System.IO.Directory.GetCurrentDirectory().ToString();
                string strTempFileName = strDirectory + @"\temp000.docx";
                Clipboard.Clear();

                _Word._Application _wardApp = new _Word.Application();
                _wardApp.Visible = false;
                _Word._Document _wordDoc = null;
                object missing = System.Reflection.Missing.Value;
                object filename = strTempFileName;
                object readOnly = false;
                object isVisible = false;
                _wordDoc = _wardApp.Documents.Add(missing, missing, missing, isVisible);
                _Word.Paragraph _wordPara = _wordDoc.Content.Paragraphs.Add(ref missing);
                _Word.Range _wordRange = _wordDoc.Paragraphs[1].Range;

                #region 将RichTextBox的内容存储到临时word文档中
                try
                {       
                    //建立word工作

                    rtxbContent.SelectAll();
                    rtxbContent.ClipboardCopy();

                                        **//暂时使用了一个弹出窗口解决的**.                                       
                    MessageBox.Show("正在生成文件,请点击以确认","确信生成");



                    _wordDoc.Activate();       

                    _wordRange.Paste();   

                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "失败啦!<( ̄︶ ̄)>");
                    _wordRange.Paste();     

                }
                //保存word文档
                _wordDoc.SaveAs2(filename, missing, missing, missing, missing, missing, missing, missing,
                    missing, missing, missing, missing, missing, missing, missing, missing, missing);
                //退出word
                _wardApp.Quit(true, missing, missing);

                MessageBox.Show("保存成功", "成功啦");


                #endregion
查看全部
yexuanbaby
圆滚滚的胖狸
2015/06/02 11:57
  • c#
  • 延时
  • word
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

4个回复