Bot.SendDocumentAsync(tgId,streamFile,"文件已发送!",false); throw exception其他信息:将内容复制到流时出错

时间:2017-06-07 07:57:43

标签: c# telegram-bot

我创建了一个异步方法,它的任务是根据用户请求将文件发送到电报服务器(然后电报机器人可以将文件发送给用户),当用户有限但当并发用户数增加时,它工作正常项目崩溃,抛出异常

  

抛出异常:' System.Net.Http.HttpRequestException'在mscorlib.dll中

     

其他信息:将内容复制到流时出错。

我试图不使用"使用"并处理它但它没有运行并立即抛出同样的错误,

我的问题是我的方法正确而且只是电报错误?如果是这样,创建队列或已发送文件的哈希映射会对我有帮助吗?

public static async void sendFileToUser(long tgId, int fileId)
    {
    ExceptionDispatchInfo capturedException = null;
    String occuredException = "";
    try
    {
    string pathPhysical1 = (string)myHT[fileId];

    using (

    var fs = new FileStream(pathPhysical1, FileMode.Open,FileAccess.Read, FileShare.Read, 1000, false))
    {

                        string fileName = fileId + ".pdf";
                        FileToSend streamFile = new FileToSend(fileName, fs);

                        await Bot.SendDocumentAsync(tgId, streamFile, "file sended", false);
                        await Bot.SendChatActionAsync(tgId, ChatAction.UploadDocument);

                    }
                }
            }
            catch (System.Net.Http.HttpRequestException ex)
            {
                capturedException = ExceptionDispatchInfo.Capture(ex);
                occuredException = "System.Net.Http.HttpRequestException";

            }
            catch (ApiRequestException ex)
            {
                capturedException = ExceptionDispatchInfo.Capture(ex);
                occuredException = "ApiRequestException";


            }
            catch (TaskCanceledException ex)
            {
                capturedException = ExceptionDispatchInfo.Capture(ex);
                occuredException = "TaskCanceledException";


            }
            catch (Exception ex)
            {
                occuredException = "Exception";

                capturedException = ExceptionDispatchInfo.Capture(ex);


            }

            if (capturedException != null)
            {

                printExceptionINConsole(capturedException.SourceException, "capturedException-" + occuredException);

                      }
        }
提前谢谢 请将此问题发布给此api的创建者 https://github.com/MrRoundRobin/telegram.bot/issues/348

1 个答案:

答案 0 :(得分:0)

怎么样:

Job > Configure > Build Environment > Inject environment variables to the build process > Script Content

我认为您的信息流有问题。