简体   繁体   English

无法通过APM扩展访问TAP中的非静态方法

[英]Cannot access non-static method in TAP over APM extension

I'm new to this and I am trying to create a TAP-over-APM wrapper for the BeginConnect method for my Socket object 我是新手,我正在尝试为我的Socket对象的BeginConnect方法创建一个TAP-over-APM包装器

public static Task ConnectTaskAsync(this Socket socket, EndPoint endpoint)
{
    return TaskFactory.FromAsync(socket.BeginConnect, socket.EndConnect, endpoint, null);
}

However, I'm getting an error on the FromAsync method "Cannot access non-static method FromAsync " in static context. 但是,我在静态上下文中的FromAsync方法“无法访问非静态方法FromAsync ”时收到错误。

How should my code be like? 我的代码应该怎么样?

As the error is trying to tell you, you need an instance of TaskFactory . 由于错误试图告诉您,您需要一个TaskFactory实例。

You can use the default singleton instance ( Task.Factory ), or you can create your own using one of its constructors. 您可以使用默认的单例实例( Task.Factory ),也可以使用其构造函数之一创建自己的实例。

You can call static methods inside none static methods but you cannot call non static method inside a static method. 你可以调用static方法内none static方法,但你不能调用静态方法中的非静态方法。

So either change the FromAsync to be static or create an instance of it. 因此,要么将FromAsync更改为静态,要么创建它的实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM