The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))

wudichong 2008-12-16 02:47:18
我用C#自动导出word时,出现exception:The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER)),请问各位大哥,这是什么原因造成的?
...全文
1038 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangronghua309 2010-02-21
  • 打赏
  • 举报
回复
应该是由于你的任务管理器中word已经打开了多个进程,你调出任务管理器,然后关闭所有的winword.exe进程,然后再运行。。
sikezx 2008-12-16
  • 打赏
  • 举报
回复
private void Button13_Click(object sender, System.EventArgs e)
{
this.Datagrid4.Visible=true;
Response.Clear();
Response.Buffer= true;
Response.Charset="GB2312";
Response.AppendHeader("Content-Disposition","attachment;filename=File1.DOC");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/ms-word";
this.Datagrid4.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter (oStringWriter);
this.Datagrid4.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}
在做ASP.NET项目时,会经常遇到要导出文件的问题,如将DataGrid中的数据导出到excel文件等,经常使用的是Office中的OWC组件,这个组件提供的功能很强大,在一般的项目中都可以满足当前的需要.但是这个功能强大的组件使用起来却不是很方便,不但有版本的问题,而且代码量也相对比较大.如果要利用Respone对象和相关的IO,也可以实现到处excel/word等文件,而且使用方便.

代码如下:

System.IO.StringWriter SW = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter HTW=new System.Web.UI.HtmlTextWriter(SW);
Page.RenderControl(HTW);
//Page为要导出的对象,当前是Page,如果是DataGrid,DataList等都可以
Response.Buffer=true;


王集鹄 2008-12-16
  • 打赏
  • 举报
回复
楼主你先把调试的代码贴出来,并说明操作步骤。

让我们能看到你描述的现象先。
wudichong 2008-12-16
  • 打赏
  • 举报
回复
楼上,你给我的东西好像不合适,我只开一个document, 我就是在给这一个doc里面填充数据的时候
忽然蹦出exception来
qinhl99 2008-12-16
  • 打赏
  • 举报
回复
或者参看这里的代码,希望对你有帮助!

using System;
using Word = Microsoft.Office.Interop.Word;

namespace KeithRull.Utilities.OfficeInterop
{
public class MsWord
{
/// <summary>
/// This is the default Word Document Template file
/// </summary>
private const string defaultWordDocumentTemplate = @"Normal.dot";

/// <summary>
/// A function that merges Microsoft Word Documents that uses the default template
/// </summary>
/// <param name="filesToMerge">An array of files that we want to merge</param>
/// <param name="outputFilename">The filename of the merged document</param>
/// <param name="insertPageBreaks">Set to true if you want to have page breaks inserted after each document</param>
public static void Merge(string[] filesToMerge, string outputFilename, bool insertPageBreaks)
{
Merge(filesToMerge, outputFilename, insertPageBreaks, defaultWordDocumentTemplate);
}

/// <summary>
/// A function that merges Microsoft Word Documents that uses a template specified by the user
/// </summary>
/// <param name="filesToMerge">An array of files that we want to merge</param>
/// <param name="outputFilename">The filename of the merged document</param>
/// <param name="insertPageBreaks">Set to true if you want to have page breaks inserted after each document</param>
/// <param name="documentTemplate">The word document you want to use to serve as the template</param>
public static void Merge(string[] filesToMerge, string outputFilename, bool insertPageBreaks, string documentTemplate)
{
object defaultTemplate = documentTemplate;
object missing = System.Type.Missing;
object pageBreak = Word.WdBreakType.wdPageBreak;
object outputFile = outputFilename;

// Create a new Word application
Word._Application wordApplication = new Word.Application();

try
{
// Create a new file based on our template
Word._Document wordDocument = wordApplication.Documents.Add(
ref defaultTemplate
, ref missing
, ref missing
, ref missing);

// Make a Word selection object.
Word.Selection selection = wordApplication.Selection;

// Loop thru each of the Word documents
foreach (string file in filesToMerge)
{
// Insert the files to our template
selection.InsertFile(
file
, ref missing
, ref missing
, ref missing
, ref missing);

//Do we want page breaks added after each documents?
if (insertPageBreaks)
{
selection.InsertBreak(ref pageBreak);
}
}

// Save the document to it's output file.
wordDocument.SaveAs(
ref outputFile
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing);

// Clean up!
wordDocument = null;
}
catch (Exception ex)
{
//I didn't include a default error handler so i'm just throwing the error
throw ex;
}
finally
{
// Finally, Close our Word application
wordApplication.Quit(ref missing, ref missing, ref missing);
}
}
}
}


qinhl99 2008-12-16
  • 打赏
  • 举报
回复
如果楼主英语好的话,可以看这里的一个文章,应该可以帮助你!http://devpinoy.org/blogs/keithrull/archive/2007/05/23/how-to-merge-multiple-microsoft-word-documents-in-c.aspx
qinhl99 2008-12-16
  • 打赏
  • 举报
回复
up
wudichong 2008-12-16
  • 打赏
  • 举报
回复
楼上,我做的效果是这样的:按一下按钮,开一个进度条,然后走啊,走啊,走到半道上,发现exception,被我catch住,弹出Messagebox来告诉用户
按你说的等待再调用,我应该做成什么效果呢,能具体一点吗?
gomoku 2008-12-16
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 wudichong 的回复:]
楼上,不行啊,我是按一个按钮,然后开线程,导出word,有的机器上一旦出现这个问题,无论调用多少次,还是出现exception
给个具体可行的办法吧?
[/Quote]

这就要看你的调试功力了 :)

如果"...F10单步跟踪的时候没问题...",该问题一般跟争抢有关系(或者说跟时间有关系)。
而针对RPC_E_SERVERCALL_RETRYLATER的常见处理,就是等待再调用。
wudichong 2008-12-16
  • 打赏
  • 举报
回复
楼上,不行啊,我是按一个按钮,然后开线程,导出word,有的机器上一旦出现这个问题,无论调用多少次,还是出现exception
给个具体可行的办法吧?
gomoku 2008-12-16
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wudichong 的回复:]
楼上,那我该如何解决这个问题呢
[/Quote]

[Quote=引用 1 楼 gomoku 的回复:]
...等一小会再调用一次。
...待会再试(RETRYLATER)
[/Quote]
wudichong 2008-12-16
  • 打赏
  • 举报
回复
楼上,那我该如何解决这个问题呢
gomoku 2008-12-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wudichong 的回复:]
我用F10单步跟踪的时候没问题,只要一按F5,就出现exception了
而且,在有的电脑上经常出现exception,而有些电脑怎么弄都不出

我开了一个线程来create document,exception是出现在线程里面

出现exception的原因是什么?
[/Quote]

当word正忙于做一件事的时候,你要它再做其他一件事,一种处理方式就是它告诉你待会儿再来。
比如如果word正在运行一段耗时的宏命令来格式文本,如果收到一个添加文本的命令,它就会返回RPC_E_SERVERCALL_RETRYLATER。

wudichong 2008-12-16
  • 打赏
  • 举报
回复
我用F10单步跟踪的时候没问题,只要一按F5,就出现exception了
而且,在有的电脑上经常出现exception,而有些电脑怎么弄都不出

我开了一个线程来create document,exception是出现在线程里面

出现exception的原因是什么?
wudichong 2008-12-16
  • 打赏
  • 举报
回复
我用F10单步跟踪的时候没问题,只要一按F5,就出现exception了
而且,在有的电脑上经常出现exception,而有些电脑怎么弄都不出

我开了一个线程来create document,exception是出现在线程里面

出现exception的原因是什么?
cpio 2008-12-16
  • 打赏
  • 举报
回复

调试一下,看具体是哪一句代码导致这种情况的
gomoku 2008-12-16
  • 打赏
  • 举报
回复
这个异常并不严重,或者说它并不一定是错误。
一般处理这种异常的方式就是,等一小会再调用一次。

其实英文说的也很清楚:待会再试(RETRYLATER)

110,552

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧