加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C#中的事件注册范围

发布时间:2020-12-15 17:22:29 所属栏目:百科 来源:网络整理
导读:可能因为GC资源释放而无法调用’已完成’事件处理程序? public void StartVideo(WerCamera camera) { Credential creadential = new Credential() { Email = CurrentUser.Email,Password = CurrentUser.Password,SessionNumber = SessionNumber}; CommandsC
可能因为GC资源释放而无法调用’已完成’事件处理程序?

public void StartVideo(WerCamera camera)
    {
        Credential creadential = new Credential() { Email = CurrentUser.Email,Password = CurrentUser.Password,SessionNumber = SessionNumber};
        CommandsClient client = new CommandsClient();
        client.StartVideoCompleted += client_StartVideoCompleted;
        client.StartVideoAsync(int.Parse(camera.Id),creadential,ClientInfo);

        client.CloseAsync();
    }

解决方法

是的,这是可能的,因为一旦函数返回,您将丢失对客户端的所有引用.

client.StartVideoCompleted = client_StartVideoCompleted;最终使用client_StartVideoCompleted函数保持对该对象的引用,但这不是往复的.您需要以某种方式保持对创建的客户端的引用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读