protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    if (this.cloudWatchClient != null)
                    {
                        this.cloudWatchClient.Dispose();
                        this.cloudWatchClient = null;
                    }

                    this.sender = null;
                }

                _disposed = true;
            }
        }
        public void Start(CounterSampleSenderBase sender)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("Resource was disposed.");
            }

            if (this.sender != null)
            {
                throw new InvalidOperationException("Already started(), can't call for second time");
            }

            this.sender = sender;

            if (this.sender.SendInterval < MinSendInterval)
            {
                throw new ArgumentOutOfRangeException("sender", "sender.SendInterval is out of range. Min value is " + MinSendInterval);
            }

            // Dimension of InstanceId
            if (!String.IsNullOrEmpty(this.settings.AWSInstanceIdLookupUrl))
            {
                try
                {
                    this.instanceId = new WebClient().DownloadString(this.settings.AWSInstanceIdLookupUrl);
                }
                catch (Exception e)
                {
                    // This will fail if running machine is not in AWS EC2
                    Log.Error(e);
                    Log.WarnFormat(
                        "Failed to retrieve AWS instance id. Use hostname {0} instead. Lookup URL was: {1}",
                        this.instanceId,
                        this.settings.AWSInstanceIdLookupUrl);
                }
            }

            // Dimension of AutoScalingGroup
            if (!String.IsNullOrEmpty(this.settings.AutoScalingConfigFilePath))
            {
                try
                {
                    var autoScalingConfigFile = new FileInfo(this.settings.AutoScalingConfigFilePath);
                    if (!autoScalingConfigFile.Exists)
                    {
                        Log.WarnFormat("AutoScalingConfigFile not found: {0}",
                                       this.settings.AutoScalingConfigFilePath);
                    }
                    else
                    {
                        using (var sr = new StreamReader(autoScalingConfigFile.FullName))
                        {
                            this.autoScalingGroupName = sr.ReadToEnd().Trim();
                        }

                        Log.InfoFormat(
                            "AutoScalingGroupName {0} read from config file {1}",
                            this.autoScalingGroupName,
                            autoScalingConfigFile.FullName);
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e);
                    Log.WarnFormat(
                        "Failed to read AutoScalingGroupName from config file {0}",
                        this.settings.AutoScalingConfigFilePath);
                }
            }

            // Amazon AWS CloudWatch Client init
            this.cloudWatchClient =
                new AmazonCloudWatchClient(
                    this.settings.AWSCloudWatchAccessKey,
                    this.settings.AWSCloudWatchSecretKey, new AmazonCloudWatchConfig
            {
                ServiceURL = this.settings.AWSCloudWatchServiceUrl.OriginalString
            });
        }