Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))

与世无争的帅哥 提交于 2019-11-29 08:20:06
pie

As Andrew Barber point out that my way cause performance loss when handling exception.

And the article referenced by Hans Passant did provide a GREAT way with option 3.

----below will cause performance loss

when it is busy, need a retry after some period of time.

may this function be helpful to retry

use lambda (delegate) as parameter

Usage 1

var selectionLocal = selection; 
var range = RunWithOutRejected(() => selectionLocal.Range);

Usage 2

RunWithOutRejected(
   () =>
       following.Value.Range.FormattedText.HighlightColorIndex =
         WdColorIndex.wdGray25);

Usage 3

var nameLocal = name;
var bookmark = RunWithOutRejected(() =>  
   winWordControl
   .GetDocument()
   .Bookmarks.Add(nameLocal, range));
name = RunWithOutRejected(() => bookmark.Name);
return new KeyValuePair(name, bookmark);

ps: when interop MSword using this function, the code _application.Selection.PasteSpecial(); failed


    public static T RunWithOutRejected<T>(Func<T> func)
    {
        var result = default(T);
        bool hasException;

        do
        {
            try
            {
                result = func();
                hasException = false;
            }
            catch (COMException e)
            {
                if (e.ErrorCode == -2147418111)
                {
                    hasException = true;
                }
                else
                {
                    throw;
                }
            }
            catch (Exception)
            {
                throw;
            }
        } while (hasException);

        return result;
    }
}

i had the same problem, after upgrading to office 2016 from office 2010 (win 10 64 bit), my problem : word was not the default program for editing document, so i made word as default program from "Control Panel\All Control Panel Items\Default Programs\Set Default Programs" and it solved.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!