I am consuming a third-party library in my .NET C# application. Essentially, the library exposes one method and one property; a pared-down representation of the interface I'm working is:
public interface IDisconnect
{
bool IsDisconnected { get; }
void Disconnect();
}
At some point after calling the method Disconnect()
, when the disconnect operation completes, the property IsDisconnected
gets set to true
. The third-party developer would have made things a lot easier if they'd implemented a OnDisconnectComplete
event (or similar) for me to subscribe to, but, given that they haven't, are there any elegant ways to listen for a property change in a third-party libraries built in to the .NET framework?
答案 0 :(得分:1)
根据提供的信息,有一个非常难看的解决方案,创建通知程序类,它将获得IDisconnect的实例。在这里,您可以设置定时器以定期检查IsDisconnected的值,如果它发生变化,则引发IDisconnnect本身的事件。定时器设置由您决定。