代码之家  ›  专栏  ›  技术社区  ›  Iman Fakhari

长轮询api程序不会使多线程在用户之间产生差异

  •  -1
  • Iman Fakhari  · 技术社区  · 7 年前

    全球的asax公司 并在Application_Start()中调用它,当我启动project telegram bot时,它会正常工作,直到有一个用户,当第二个用户开始使用bot时,用户第二个用户更新不会产生另一个线程,并且它会在第一个用户进程的后续进程中工作!

    例如: 用户#1以“AnswerForm”的形式发送消息(更新),以便bot通过第一个条件并等待用户在长轮询周期内输入表单Id,在这段时间内,当另一个用户启动bot并向其发送消息时,bot将其作为用户1表单Id接收!我猜想这会为他带来另一条线索,但我不知道我没有发生。那么我该如何解决这个问题呢?

    static async void testApiAsync()
    {
        try
        {
            var Bot = new Telegram.Bot.TelegramBotClient("my_token");
            var me = await Bot.GetMeAsync();
            int offset = 0;
            while (true)
            {
                var updates = await Bot.GetUpdatesAsync(offset);
                foreach (var update in updates)
                {
                    offset = update.Id + 1; //new offset id
                    if (update.Message != null)
                    {
                        if (update.Message.Text == "AnswerForm")
                        {
                            string askFormId = "send Form Id";
                            await Bot.SendTextMessageAsync(update.Message.Chat.Id, askFormId);
                            while (true)
                            {
                                //here was my code that
                                //wait for user to enter Form Id
                            }
                        }
                    }
                }
            }
        }
        catch { }
    }
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Iman Fakhari    7 年前

    我发现了问题!它又深又大!在这个api中,用户不提交任何东西,在服务器中,我不连续接收线程来验证每个用户!

    使用在数据库中保存会话跟踪每个用户