在 get set 属性中,只有在设置了值之后才返回值。我使用了响应式库并订阅了它在不同线程上运行的消息。当引发事件并设置值时,捕获值并返回。
internal PinMessage()
{
obj.PinsAvailable.ObserveOn(SynchronizationContext.Current).Subscribe(HandlePinsAvailable);
}
private void HandlePinsAvailable(byte[] pinBytes)
{
pinmesssage = Encoding.ASCII.GetString(pinBytes);
}
public void Readvalue(object stringobj)
{
pinmesssage = (string)stringobj;
}
internal string GetPinMessage(string AccoutNumber)
{
string pinstring = string.Empty;
obj.SendPinRequest(AccoutNumber);
t1.Join();
pinstring = pinmesssage;
return pinstring;
}
private string _pinMessafe;
public string pinmesssage
{
get
{
//Get value only when the property is set
return _pinMessafe;
}
set { _pinMessafe = value; }
}