【发布时间】:2017-01-16 13:01:47
【问题描述】:
我尝试使用TLSharp v 0.1.0.209 为 Telegram 开发一个客户端,除了接收消息并在其内容上运行一些简单的逻辑之外什么都不做
我的代码目前看起来像这样
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TLSharp.Core;
namespace TelegramBot
{
public sealed class Service
{
private TelegramClient client;
public Service()
{
this.client = new TelegramClient(etc.Constants.AppApiId, etc.Constants.AppApiHash);
}
public async void Connect()
{
await this.client.ConnectAsync();
}
public async void Authenticate(String phoneNumber)
{
var hash = await client.SendCodeRequestAsync(phoneNumber);
{
Debugger.Break();
}
var code = "<code_from_telegram>"; // you can change code in debugger
var user = await client.MakeAuthAsync(phoneNumber, hash, code);
}
}
}
我这样称呼它
static void Main(string[] args)
{
Service bot = new Service();
bot.Connect();
bot.Authenticate(etc.Constants.PhoneNumber);
Debugger.Break();
}
但是,我在调用“SendCodeRequestAsync”时收到“NullPointerException”。我该如何解决/解决这个问题?该号码以“+12223334444”的格式提供
【问题讨论】:
-
为什么是
async void?