我想知道是否有一種方法讓一個類的實例在運行時保留數據的同時訪問其父類的方法。 (這是否有意義?)C#從另一個文件訪問父類方法
如果有多個COM端口設置,我有一個ConnectionManager產生多個連接器(它負責COM端口通信)。
file1.cs
namespace connector
{
public class connectormanager : idisposable
{
public connectormanager(comport1, comport2, retries, delay)
{
// create dictionary that maps COMPorts with devices
// **foreach spawn connector (if com port range is given)**
}
public searchchannel()
{
// search existing com ports
}
}
}
file2.cs
namespace connector
{
public class connector : idisposable
{
public void connector(port, retries, delay)
{
// there is a timer with a timeout event defined
}
// com port read/write operations
void _timer_Elapsed()
{
// **i want to access searchchannel**
// problem is if i create a new instance of connectionmanager
// i lose all the dictionary stuff
}
}
}
這兩個文件都在同一個解決方案和項目下。我想要做的是從file2.cs中的_timer_Elapsed訪問搜索頻道,而無需創建連接器管理器的新實例。
任何意見或幫助非常感謝。
謝謝主席先生,這工作就像一個魅力! – mastofact 2010-10-14 21:24:08