private void dgResult_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex > -1 && dgResult.Columns[e.ColumnIndex].Name == "ColServerName")
     {
         ServerLoadHelper.ConnectToRemoteDesktop(dgResult[e.ColumnIndex, e.RowIndex].Value.ToString(),
                                                 dgResult["ColUserName", e.RowIndex].Value.ToString(),
                                                 dgResult["ColPassword", e.RowIndex].Value.ToString());
     }
 }
        private void GetServerUsageAsyncForMail(object param)
        {
            if (param == null || !(param is ServerConfigurationData))
            {
                //Report Error
                this.BeginInvoke(new Action(() =>
                {
                    MessageBox.Show("Invalid argument: param", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }));
                iServer++;
                if (iServer == cntServer)
                {
                    if (emailBody != string.Empty)
                    {
                        SendEmail();
                    }
                    iServer = 0;
                }
                return;
            }

            ServerConfigurationData configuration = param as ServerConfigurationData;

            try
            {
                ServerLoadData result = ServerLoadHelper.GetServerUsage(configuration.ServerName, configuration.UserName, configuration.Password);

                iServer++;
                //Complete
                this.BeginInvoke(new Action <ServerLoadData>(OnGetServerUsageAsyncCompletedForMail), result);
            }
            catch (Exception ex)
            {
                iServer++;
                if (iServer == cntServer)
                {
                    if (emailBody != string.Empty)
                    {
                        SendEmail();
                    }
                    iServer = 0;
                }
                //Report Error
                this.BeginInvoke(new Action <string, Exception>(ReportErrorForEmail), configuration.ServerName, ex);
            }
        }
        private void GetServerUsageAsync(object param)
        {
            if (param == null || !(param is ServerConfigurationData))
            {
                iMonitorServer++;
                //Report Error
                this.BeginInvoke(new Action(() =>
                {
                    if (iMonitorServer == cntMonitorServer)
                    {
                        btnRefresh.Enabled = true;
                        iMonitorServer     = 0;
                    }
                    MessageBox.Show("Invalid argument: param", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }));
                return;
            }

            ServerConfigurationData configuration = param as ServerConfigurationData;

            //Report Progress
            this.BeginInvoke(new Action <string, decimal>(ReportProgress), configuration.ServerName, new Decimal(0));

            try
            {
                ServerLoadData result = ServerLoadHelper.GetServerUsage(configuration.ServerName, configuration.UserName, configuration.Password);

                iMonitorServer++;
                //Complete
                this.BeginInvoke(new Action <ServerLoadData>(OnGetServerUsageAsyncCompleted), result);
            }
            catch (Exception ex)
            {
                iMonitorServer++;
                //Report Error
                this.BeginInvoke(new Action <string, Exception>(ReportError), configuration.ServerName, ex);
            }
        }