internal HeartRateForm( IHeartRateService service, string settingsFilename, DateTime now) { try { // Order of operations -- _startedAt has to be set before // `LoadSettingsLocked` is called. _startedAt = now; _settings = HeartRateSettings.CreateDefault(settingsFilename); LoadSettingsLocked(); _settings.Save(); _service = service; _iconBitmap = new Bitmap(_iconWidth, _iconHeight); _iconGraphics = Graphics.FromImage(_iconBitmap); _measurementFont = new Font( _settings.FontName, _iconWidth, GraphicsUnit.Pixel); _watchdog = new HeartRateServiceWatchdog( TimeSpan.FromSeconds(10), _service); InitializeComponent(); FormBorderStyle = _settings.Sizable ? FormBorderStyle.Sizable : FormBorderStyle.SizableToolWindow; } catch { service.TryDispose(); throw; } }
protected override void Dispose(bool disposing) { if (disposing) { components.TryDispose(); lock (_disposeSync) { _service.TryDispose(); _iconBitmap.TryDispose(); _iconGraphics.TryDispose(); _measurementFont.TryDispose(); _iconStringFormat.TryDispose(); _watchdog.TryDispose(); } } base.Dispose(disposing); }