c# - 电报消息的OpenTl自动更新引发错误CS0079 C#

标签 c# error-handling compiler-errors

我最近尝试使用OpenTL快速入门页上的自动更新示例,仅使用以下基本示例

await clientApi.UpdatesService.AutoReceiveUpdates += update =>
{
// Handle updates
 switch (update)
    {
        case TUpdates updates:
            break;
        case TUpdatesCombined updatesCombined:
            break;
        case TUpdateShort updateShort:
            break;
        case TUpdateShortChatMessage updateShortChatMessage:
            break;
        case TUpdateShortMessage updateShortMessage:
            break;
        case TUpdateShortSentMessage updateShortSentMessage:
            break;
        case TUpdatesTooLong updatesTooLong:
            break;
    }
};
它不会编译抛出此错误:

Error CS0079 The event 'IUpdatesService.AutoReceiveUpdates' can only appear to the left of += or -=


我将其放入异步Task函数中,但我认为这不是问题。我真的不知道如何使用这样的异步事件。
link to the example

最佳答案

您写的方式是错误的。它应该是

clientApi.UpdatesService.AutoReceiveUpdates += async update => 
{
// Handle updates
 switch (update)
    {

关于c# - 电报消息的OpenTl自动更新引发错误CS0079 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64806756/

相关文章:

编译器错误: control reaches end of non-void function

compiler-errors - 错误: expected ‘ ; ’ before ‘ { ’ token (c++) [closed]

php - PHP错误处理,表单仍在提交?

c# - ASP.NET Global.asax Application_Error 有效但在使用 Error 事件时无效

ruby - 如何验证ruby cucumber中抛出的异常

c# - 从 C# 调用 JavaScript 时出现错误 UnathorizedException

c# - 扩展方法必须在非泛型静态类中定义

c# - 将 List<T> 设置为 linq 查询结果导致超时

c# - 如果在信号量的情况下多个线程抛出异常怎么办

c# - OrmLite.SqlServer 程序集出错