0
public class RSensor : IRSensor
{
public RSensorType SensorType { get; protected set; }
public event EventHandler ConnectionLost;
public void Configure(Stream input, Stream output, RSensorType type, ISensorReciever reciever)
{
throw new NotImplementedException();
}
public RSensor()
{
}
}
我有一個類RSensor
有一個事件處理程序ConnectionLost
當連接出現故障,它將通知我。寫事件處理器來管理連接在C#
我有另一個類ConnectionManager
,當連接斷開時需要處理。我在這個類中創建了一個虛擬函數 。如何觸發此功能,當EventHandler ConnectionLost
從RSensor
類被觸發。
public class ConnectionManager
{
ActiveList m_ActiveList;
Dictionary<IRionSensor, VSManager> m_ConnectionManager;
class VehicleStreamManager
{
public IVehicle Vehicle { get; set; }
public NetworkStream AStream { get; set; }
public NetworkStream BStream { get; set; }
}
ConnectionManager(ActiveExercise exercise)
{
m_ActiveList = exercise;
m_ConnectionManager = new Dictionary<IRSensor, VehicleStreamManager>();
}
void Connect()
{
List<VehicleStreamManager> vsmList;
VehicleStreamManager vsm;
vsm = InitiateAVehicleConnections();
m_ConnectionManager.Add(null, vsm);
vsmList = InitiateBVehicleConnections();
foreach(var item in vsmList)
{
RSensor fsensor = new RSensor();
fsensor.Configure(item.AStream, item.BStream, RSensorType.RSensor_Both, null);
m_ConnectionManager.Add(fsensor, item);
}
}
void HandleConnectionLost()
{
//Do some stuff
}
}
}
這裏'對象發件人'是傳感器對象? – liv2hak
@ liv2hak是的。發件人將成爲傳感器。 – Optimax