TLSharp在启动时挂起

时间:2017-07-21 05:56:16

标签: c# android telegram

我的应用程序中有一个用于处理Telegram的课程。它使用TLSarp库。它有以下代码进行初始化:

    public TelegramBridge()
    {
        client = CreateClient();
        InitializeAndAuthenticateClient(client).Wait();
    }

    public TelegramClient CreateClient()
    {
        TelegramClient clt = null;

        clt = new TelegramClient(apiID, apiHash, _sessionStore, "/mnt/sdcard/smsservice/session");

        return clt;
    }

    public async Task<TelegramClient> InitializeAndAuthenticateClient(TelegramClient cli)
    {
        try
        {
            await cli.ConnectAsync();
            if (cli.IsUserAuthorized())
            {
                Logger.Info("User is authorized already");
            }
            else
            {
                Logger.Error("User is not authorized");
                var codeRequest = await cli.SendCodeRequestAsync(registeredPhone);
                var user = await cli.MakeAuthAsync(registeredPhone, codeRequest, code);
            }

            if (cli.IsUserAuthorized() == true)
            {
                Logger.Info("Successful autorization");
                return cli;
            }
            else
            {
                Logger.Error("Authorization failed");
                return null;
            }
        }
        catch (Exception e)
        {
            Logger.Error("Telegram Client Auth exception: " + e.Message);
            return null;
        }
    }

但是当我从另一个类函数调用构造函数时,InitializeAndAuthenticateClient在调用时挂起

                await cli.ConnectAsync();

另一方面,如果我在TelegramBridge类的任何其他函数内调用此函数,它可以正常工作。谁能解释一下我的错误在哪里?

0 个答案:

没有答案