IWxStation m_station = null; /* reference to assy */ /* testing is now much easier because we swap in the simulator with a cmd line option */ public MainWindow() { InitializeComponent(); m_cmdArgs = Environment.GetCommandLineArgs(); // check to see if we want wx server or wx simulator if ((m_cmdArgs[1].Split(new char[] { ':' })[1].Equals("true"))) { m_station = new WxStation(); /* concrete instantiation; must consider thrown exceptions */ } else if ((m_cmdArgs[1].Split(new char[] { ':' })[1].Equals("false"))) { m_station = new WxStationSim(); /* concrete instantiation; must consider thrown exceptions */ } m_station.Initialize(); m_mreRun = new ManualResetEvent(false); // Sets the state of the event to not signaled, causing one or more threads to block. }
IWxStation m_station = null; /* reference to assy */ /* testing is now much easier because we swap in the simulator with a cmd line option */ public MainWindow() { InitializeComponent(); m_cmdArgs = Environment.GetCommandLineArgs(); if ((m_cmdArgs[1].Split(new char[] { ':' })[1].Equals("true"))) { m_station = new WxStation(); /* concrete instantiation; must consider thrown exceptions */ } else if ((m_cmdArgs[1].Split(new char[] { ':' })[1].Equals("false"))) { m_station = new WxStationSim(); /* concrete instantiation; must consider thrown exceptions */ } m_station.Initialize(); m_mreRun = new ManualResetEvent(false); // tell the server that we want updates for the following information m_station.ChangedTemperature += m_station_ChangedTemperature; m_station.ChangedWindDirection += m_station_ChangedWindDirection; m_station.ChangedWindSpeed += m_station_ChangedWindSpeed; m_station.ChangedSetting += m_station_ChangedSetting; }
/* testing is now much easier because we swap in the simulator with a cmd line option */ public MainWindow() { InitializeComponent(); m_cmdArgs = Environment.GetCommandLineArgs(); // REQUIRES ref to IWxStation_Extended at build time even we don't use it at runtime if ((m_cmdArgs[1].Split(new char[] { ':' })[1].Equals("true"))) { m_station = new WxStation(); // concrete instantiation; must consider thrown exceptions } else if ((m_cmdArgs[1].Split(new char[] { ':' })[1].Equals("false"))) { m_station = new WxStationSim(); // concrete instantiation; must consider thrown exceptions } m_station.Initialize(); // ManualResetEvent is a good way to avoid the bool bContinue = true; while (bContinue) { ... } snippet. // WaitOne(int msec) returns false if reset/unsignaled and true if set/signaled. m_mreRun = new ManualResetEvent(false); // must cast because += operator can not be applied to type dynamic and method group ((IWxStation)m_station).ChangedTemperature += m_station_ChangedTemperature; ((IWxStation)m_station).ChangedWindDirection += m_station_ChangedWindDirection; ((IWxStation)m_station).ChangedWindSpeed += m_station_ChangedWindSpeed; ((IWxStation)m_station).ChangedSetting += m_station_ChangedSetting; }