private void cmdRemoteCommandExecute_Click(object sender, EventArgs e)
        {
            List<DescribeDevicePackageType> describeDeviceColl = new List<DescribeDevicePackageType>();
            List<RemoteCommandResultType> remoteCommandResltLst = new List<RemoteCommandResultType>();
            for (int row = 0; row < dgvPendingRemoteCommands.Rows.Count; row++)
            {
                try
                {
                    if (this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_CHK] != null &&
                        this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_CHK].Value != null &&
                        (bool)this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_CHK].Value == true &&
                        this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_ID].Value != null)
                    {
                        DescribeDevicePackageType describeDevice = new DescribeDevicePackageType();
                        if (this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_DEVICEID].Value != null)
                        {
                            describeDevice.DeviceGUID = Convert.ToString(this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_DEVICEID].Value);
                        }
                        DeviceDescriptionType deviceDescriptionType = new DeviceDescriptionType();
                        if (this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_DESC].Value != null)
                        {
                            deviceDescriptionType.Description = Convert.ToString(this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_DESC].Value);
                        }

                        deviceDescriptionType.DeviceGUID = describeDevice.DeviceGUID;
                        if (this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_IP].Value != null)
                        {
                            deviceDescriptionType.IPAddress = Convert.ToString(this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_IP].Value);
                        }
                        if (this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_LOGICALID].Value != null)
                        {
                            deviceDescriptionType.LogicalDeviceID = Convert.ToString(this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_LOGICALID].Value);
                        }
                        if (this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_MAC].Value != null)
                        {
                            deviceDescriptionType.MACAddress = Convert.ToString(this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_MAC].Value);
                        }
                        if (this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_MANF].Value != null)
                        {
                            deviceDescriptionType.Manufacturer = Convert.ToString(this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_MANF].Value);
                        }
                        if (this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_MODEL].Value != null)
                        {
                            deviceDescriptionType.Model = Convert.ToString(this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_MODEL].Value);
                        }
                        if (this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_SERIAL_NUMBER].Value != null)
                        {
                            deviceDescriptionType.SerialNumber = Convert.ToString(this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_SERIAL_NUMBER].Value);
                        }
                        if (this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_HOST].Value != null)
                        {
                            deviceDescriptionType.HostName = Convert.ToString(this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_HOST].Value);
                        }
                        if (this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_SW_VER].Value != null)
                        {
                            deviceDescriptionType.SoftwareVersion = Convert.ToString(this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_SW_VER].Value);
                        }
                        if (this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_DEVICE_TYPE].Value != null)
                        {
                            deviceDescriptionType.Type = Convert.ToString(this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_DEVICE_TYPE].Value);
                        }
                        describeDevice.DeviceDescription = deviceDescriptionType;

                        DeviceStatusesType deviceStatusType = new DeviceStatusesType();
                        deviceStatusType.ServiceStatus = 0;
                        deviceStatusType.Status = 4;
                        deviceStatusType.StatusDate = DateTime.Now;

                        describeDevice.DeviceStatus = deviceStatusType;
                        describeDeviceColl.Add(describeDevice);
                        RemoteCommandResultType resultType = new RemoteCommandResultType();
                        resultType.Status = 2;
                        if (this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_ID].Value != null)
                        {
                            resultType.ID = Convert.ToString(this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_ID].Value);
                        }
                        if (this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_INSTNCE_ID].Value != null)
                        {
                            resultType.InstanceID = Convert.ToString(this.dgvPendingRemoteCommands.Rows[row].Cells[GRD_RMCD_INSTNCE_ID].Value);
                        }
                        resultType.Message = "Reply send by simulator";
                        resultType.Status = 2;
                        remoteCommandResltLst.Add(resultType);
                    }
                }
                catch { }
            }
            //for (int i = 0; i < describeDeviceColl.Count; i++)
            //{
            //    RemoteCommandResultType _remoteCmdResult = new RemoteCommandResultType();
            //    _remoteCmdResult = remoteCommandResltLst[i];
            //    proxy.RemoteCommandReply(_remoteCmdResult);
            //    DescribeDevicePackageType _describeDevicePkgType = new DescribeDevicePackageType();
            //    _describeDevicePkgType = describeDeviceColl[i];
            //    proxy.DescribeDevice(_describeDevicePkgType);
            //}

            try
            {
                int j = 0;
                foreach (var item in describeDeviceColl)
                {
                    j = j + 1;
                    Thread SenddescribeDevicePackageType = new Thread(() => { LogAndSendDescribeDevicePackage(item, "Thread" + j.ToString()); });
                    SenddescribeDevicePackageType.Name = "Thread" + j.ToString();
                    SenddescribeDevicePackageType.Start();
                    System.Threading.Thread.Sleep(20);
                }
                j = 0;
                foreach (var item in remoteCommandResltLst)
                {
                    j = j + 1;
                    Thread SendRemoteCommandResult = new Thread(() => { LogAndSendRemoteCommandReplyPackage(item, "Thread" + j.ToString()); });
                    SendRemoteCommandResult.Name = "Thread" + j.ToString();
                    SendRemoteCommandResult.Start();
                    System.Threading.Thread.Sleep(20);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            System.Threading.Thread.Sleep(4000);
            _ManualResetEvent.Set();
            System.Threading.Thread.Sleep(4000);
            _ManualResetEvent.Reset();
        }
        private void SendSendAlertPackageForPerformance()
        {
            List<AlertPackageType> lstAlertPackageType = new List<AlertPackageType>();
            for (int i = 0; i <= nCurrentRow_SendAlert; i++)
            {
                if (this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_DEVICE_GUID].Value != null &&
                    this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_IS_SNAPSHOT].Value != null &&
                    this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_ALERT_ID].Value != null &&
                    this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_COMPONENT_SERIAL_NO].Value != null &&
                    this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_COMPONENT_DEVICE_TYPE].Value != null &&
                    this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_IS_ALERT_REMOVED].Value != null &&
                    this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_ALERT_MESSAGE].Value != null &&
                    !string.IsNullOrEmpty(Convert.ToString(this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_DEVICE_GUID].Value)) &&
                    !string.IsNullOrEmpty(Convert.ToString(this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_IS_SNAPSHOT].Value)) &&
                    !string.IsNullOrEmpty(Convert.ToString(this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_ALERT_ID].Value)) &&
                    !string.IsNullOrEmpty(Convert.ToString(this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_COMPONENT_SERIAL_NO].Value)) &&
                    !string.IsNullOrEmpty(Convert.ToString(this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_COMPONENT_DEVICE_TYPE].Value)) &&
                    !string.IsNullOrEmpty(Convert.ToString(this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_IS_ALERT_REMOVED].Value)) &&
                    !string.IsNullOrEmpty(Convert.ToString(this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_ALERT_MESSAGE].Value)))
                {
                    AlertPackageType _alertPackageType = new AlertPackageType();
                    _alertPackageType.DeviceGUID = Convert.ToString(this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_DEVICE_GUID].Value);

                    DeviceStatusesType deviceStatusType = new DeviceStatusesType();
                    deviceStatusType.ServiceStatus = 1;
                    deviceStatusType.Status = 1;
                    deviceStatusType.StatusDate = DateTime.Now;

                    _alertPackageType.DeviceStatus = deviceStatusType;

                    RemoteAlertInstanceType _remoteAlertInstanceType = new RemoteAlertInstanceType();
                    _remoteAlertInstanceType.ComponentDeviceType = Convert.ToString(this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_COMPONENT_DEVICE_TYPE].Value);
                    _remoteAlertInstanceType.ComponentSerialNumber = Convert.ToString(this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_COMPONENT_SERIAL_NO].Value);
                    _remoteAlertInstanceType.ID = Convert.ToString(this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_ALERT_ID].Value);
                    _remoteAlertInstanceType.IsAlertRemoved = Convert.ToBoolean(this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_IS_ALERT_REMOVED].Value);
                    _remoteAlertInstanceType.Message = Convert.ToString(this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_ALERT_MESSAGE].Value);
                    _alertPackageType.RemoteAlerts = new RemoteAlertsInstanceType();
                    _alertPackageType.RemoteAlerts.IsSnapShot = Convert.ToBoolean(this.dgv_Performance_SendAlert.Rows[i].Cells[GRD_IS_SNAPSHOT].Value);
                    _alertPackageType.RemoteAlerts.IsSnapShotSpecified = true;
                    _alertPackageType.RemoteAlerts.RemoteAlert = new RemoteAlertInstanceType[1];
                    _alertPackageType.RemoteAlerts.RemoteAlert[0] = _remoteAlertInstanceType;
                    try
                    {
                        lstAlertPackageType.Add(_alertPackageType);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                        return;
                    }
                }
            }

            try
            {
                int j = 0;
                foreach (var item in lstAlertPackageType)
                {
                    j = j + 1;
                    Thread SendAlertPackageType = new Thread(() => { proxy.SendAlert(item); });
                    SendAlertPackageType.Name = "Thread" + j.ToString();
                    SendAlertPackageType.Start();
                    System.Threading.Thread.Sleep(20);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            System.Threading.Thread.Sleep(2000);
            _ManualResetEvent.Set();
            System.Threading.Thread.Sleep(2000);
            _ManualResetEvent.Reset();
        }
        //private void tbbulkdescribedevice_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        string sMsg = string.Empty;
        //        DataSet ds = new DataSet();
        //        SqlDataAdapter da = new SqlDataAdapter();
        //        string sConStr = GetTDMConnectionString;
        //        try
        //        {
        //            if (!string.IsNullOrEmpty(sConStr))
        //            {
        //                using (SqlConnection con = new SqlConnection(sConStr))
        //                {
        //                    string sCmd = "select di_AssociationId,di_LogicalDeviceId,di_DeviceType,di_Manufacturer,di_Model,di_SerialNumber " +
        //                        ",di_MACAddress,di_HostName,di_IPAddress,di_Description,di_SoftwareVersion,di_InstanceID " +
        //                        " from deviceinfo with (nolock)";
        //                    con.Open();
        //                    using (SqlCommand cmd = new SqlCommand(sCmd, con))
        //                    {
        //                        cmd.CommandText = sCmd;
        //                        da.SelectCommand = cmd;
        //                        da.Fill(ds);
        //                    }
        //                }
        //            }
        //            else
        //            {
        //                sMsg = "Invalid TDM SQL connection string";
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            sMsg = ex.ToString();
        //        }
        //        DataRow dr = ds.Tables[0].NewRow();
        //        if (ds.Tables[0].Rows.Count > 0)
        //        {
        //            Random r = new Random();
        //            int rInt = r.Next(0, ds.Tables[0].Rows.Count);
        //            dr = ds.Tables[0].Rows[rInt];//Random DeviceGuid
        //            for (int i = 0; i < 10000; i++)
        //            {
        //                foreach (DataRow _row in ds.Tables[0].Rows)
        //                {
        //                    DescribeDevicePackageType describeDevice = new DescribeDevicePackageType();
        //                    describeDevice.DeviceGUID = Convert.ToString(_row["di_AssociationId"]);
        //                    DeviceDescriptionType deviceDescriptionType = new DeviceDescriptionType();
        //                    deviceDescriptionType.Description = "Test";
        //                    deviceDescriptionType.DeviceGUID = Convert.ToString(_row["di_AssociationId"]);
        //                    deviceDescriptionType.IPAddress = Convert.ToString(_row["di_IPAddress"]);
        //                    deviceDescriptionType.LogicalDeviceID = Convert.ToString(_row["di_LogicalDeviceId"]);
        //                    deviceDescriptionType.MACAddress = Convert.ToString(_row["di_MACAddress"]);
        //                    deviceDescriptionType.Manufacturer = Convert.ToString(_row["di_Manufacturer"]);
        //                    deviceDescriptionType.Model = Convert.ToString(_row["di_Model"]);
        //                    deviceDescriptionType.SerialNumber = Convert.ToString(_row["di_SerialNumber"]);
        //                    deviceDescriptionType.HostName = Convert.ToString(_row["di_HostName"]);
        //                    deviceDescriptionType.SoftwareVersion = Convert.ToString(_row["di_SoftwareVersion"]);
        //                    deviceDescriptionType.Type = Convert.ToString(_row["di_DeviceType"]);
        //                    describeDevice.DeviceDescription = deviceDescriptionType;
        //                    DeviceStatusesType deviceStatusType = new DeviceStatusesType();
        //                    deviceStatusType.ServiceStatus = 1;
        //                    deviceStatusType.Status = 2;
        //                    deviceStatusType.StatusDate = DateTime.Now;
        //                    describeDevice.DeviceStatus = deviceStatusType;
        //                    describeDevice.RemoteAlerts = new RemoteAlertsInstanceType();
        //                    describeDevice.RemoteAlerts.IsSnapShotSpecified = true;
        //                    describeDevice.RemoteAlerts.IsSnapShot = true;
        //                    //describeDevice.RemoteAlerts = new RemoteAlertsInstanceType();
        //                    //RemoteAlertInstanceType _remoteAlertInstanceType = new RemoteAlertInstanceType();
        //                    //if (Convert.ToString(dr["di_DeviceType"]).ToLower() == "fvd")
        //                    //{
        //                    //    _remoteAlertInstanceType.ComponentDeviceType = Convert.ToString(dr["di_DeviceType"]);
        //                    //    _remoteAlertInstanceType.ComponentSerialNumber = Convert.ToString(dr["di_SerialNumber"]);
        //                    //    _remoteAlertInstanceType.ID = "7587CD17-2856-4B8F-BD8E-512D586F8B31";// Convert.ToString(dr["di_InstanceID"]);
        //                    //    _remoteAlertInstanceType.IsAlertRemoved = false;
        //                    //    _remoteAlertInstanceType.Message = "The print head temperature is below the required value.";
        //                    //    describeDevice.RemoteAlerts.RemoteAlert[0] = _remoteAlertInstanceType;
        //                    //}
        //                    proxy.DescribeDevice(describeDevice);
        //                }
        //                //DescribeDevicePackageType describeDevice = new DescribeDevicePackageType();
        //                //describeDevice.DeviceGUID = Convert.ToString(dr["di_AssociationId"]);
        //                //DeviceDescriptionType deviceDescriptionType = new DeviceDescriptionType();
        //                //deviceDescriptionType.Description = "Test";
        //                //deviceDescriptionType.DeviceGUID = Convert.ToString(dr["di_AssociationId"]);
        //                //deviceDescriptionType.IPAddress = Convert.ToString(dr["di_IPAddress"]);
        //                //deviceDescriptionType.LogicalDeviceID = Convert.ToString(dr["di_LogicalDeviceId"]);
        //                //deviceDescriptionType.MACAddress = Convert.ToString(dr["di_MACAddress"]);
        //                //deviceDescriptionType.Manufacturer = Convert.ToString(dr["di_Manufacturer"]);
        //                //deviceDescriptionType.Model = Convert.ToString(dr["di_Model"]);
        //                //deviceDescriptionType.SerialNumber = Convert.ToString(dr["di_SerialNumber"]);
        //                //deviceDescriptionType.HostName = Convert.ToString(dr["di_HostName"]);
        //                //deviceDescriptionType.SoftwareVersion = Convert.ToString(dr["di_SoftwareVersion"]);
        //                //deviceDescriptionType.Type = Convert.ToString(dr["di_DeviceType"]);
        //                //describeDevice.DeviceDescription = deviceDescriptionType;
        //                //DeviceStatusesType deviceStatusType = new DeviceStatusesType();
        //                //deviceStatusType.ServiceStatus = 1;
        //                //deviceStatusType.Status = 2;
        //                //deviceStatusType.StatusDate = DateTime.Now;
        //                //describeDevice.DeviceStatus = deviceStatusType;
        //                //proxy.DescribeDevice(describeDevice);
        //            }
        //        }
        //    }
        //    catch (InvalidOperationException ex)
        //    {
        //        MessageBox.Show(ex.Message);
        //    }
        //}
        private void button1_Click_1(object sender, EventArgs e)
        {
            try
            {
                string sMsg = string.Empty;
                DataSet ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter();
                string sConStr = GetTDMConnectionString;
                try
                {
                    if (!string.IsNullOrEmpty(sConStr))
                    {
                        using (SqlConnection con = new SqlConnection(sConStr))
                        {
                            string sCmd = "select di_AssociationId,di_LogicalDeviceId,di_DeviceType,di_Manufacturer,di_Model,di_SerialNumber " +
                                ",di_MACAddress,di_HostName,di_IPAddress,di_Description,di_SoftwareVersion,di_InstanceID " +
                                " from deviceinfo with (nolock)";
                            con.Open();
                            using (SqlCommand cmd = new SqlCommand(sCmd, con))
                            {
                                cmd.CommandText = sCmd;
                                da.SelectCommand = cmd;
                                da.Fill(ds);
                            }
                        }
                    }
                    else
                    {
                        sMsg = "Invalid TDM SQL connection string";
                    }
                }
                catch (Exception ex)
                {
                    sMsg = ex.ToString();
                }
                DataRow dr = ds.Tables[0].NewRow();
                if (ds.Tables[0].Rows.Count > 0)
                {
                    Random r = new Random();
                    int rInt = r.Next(0, ds.Tables[0].Rows.Count);
                    dr = ds.Tables[0].Rows[rInt];//Random DeviceGuid
                    if (string.IsNullOrEmpty(txtDevice.Text))
                    {
                        MessageBox.Show("Please enter device count");
                    }

                    else
                    {
                        int devicecount = Convert.ToInt32(txtDevice.Text);

                        //for (int i = 0; i < devicecount; i++)
                        for (int i = 0; i < devicecount; i++)
                        {
                            foreach (DataRow _row in ds.Tables[0].Rows)
                            {
                                try
                                {

                                    DescribeDevicePackageType describeDevice = new DescribeDevicePackageType();
                                    describeDevice.DeviceGUID = Convert.ToString(_row["di_AssociationId"]);
                                    DeviceDescriptionType deviceDescriptionType = new DeviceDescriptionType();
                                    deviceDescriptionType.Description = "Test";
                                    deviceDescriptionType.DeviceGUID = Convert.ToString(_row["di_AssociationId"]);
                                    deviceDescriptionType.IPAddress = Convert.ToString(_row["di_IPAddress"]);
                                    deviceDescriptionType.LogicalDeviceID = Convert.ToString(_row["di_LogicalDeviceId"]);
                                    deviceDescriptionType.MACAddress = Convert.ToString(_row["di_MACAddress"]);
                                    deviceDescriptionType.Manufacturer = Convert.ToString(_row["di_Manufacturer"]);
                                    deviceDescriptionType.Model = Convert.ToString(_row["di_Model"]);
                                    deviceDescriptionType.SerialNumber = Convert.ToString(_row["di_SerialNumber"]);
                                    deviceDescriptionType.HostName = Convert.ToString(_row["di_HostName"]);
                                    deviceDescriptionType.SoftwareVersion = Convert.ToString(_row["di_SoftwareVersion"]);
                                    deviceDescriptionType.Type = Convert.ToString(_row["di_DeviceType"]);
                                    describeDevice.DeviceDescription = deviceDescriptionType;
                                    DeviceStatusesType deviceStatusType = new DeviceStatusesType();
                                    deviceStatusType.ServiceStatus = 1;
                                    deviceStatusType.Status = 2;
                                    deviceStatusType.StatusDate = DateTime.Now;
                                    describeDevice.DeviceStatus = deviceStatusType;

                                    describeDevice.DeviceGUID = describeDevice.DeviceGUID;
                                    describeDevice.RemoteAlerts = new RemoteAlertsInstanceType();
                                    describeDevice.RemoteAlerts.IsSnapShotSpecified = true;
                                    describeDevice.RemoteAlerts.IsSnapShot = true;

                                    //describeDevice.RemoteAlerts = new RemoteAlertsInstanceType();
                                    //RemoteAlertInstanceType _remoteAlertInstanceType = new RemoteAlertInstanceType();
                                    //if (Convert.ToString(dr["di_DeviceType"]).ToLower() == "fvd")
                                    //{
                                    //    _remoteAlertInstanceType.ComponentDeviceType = Convert.ToString(dr["di_DeviceType"]);
                                    //    _remoteAlertInstanceType.ComponentSerialNumber = Convert.ToString(dr["di_SerialNumber"]);
                                    //    _remoteAlertInstanceType.ID = "7587CD17-2856-4B8F-BD8E-512D586F8B31";// Convert.ToString(dr["di_InstanceID"]);
                                    //    _remoteAlertInstanceType.IsAlertRemoved = false;
                                    //    _remoteAlertInstanceType.Message = "The print head temperature is below the required value.";
                                    //    describeDevice.RemoteAlerts.RemoteAlert[0] = _remoteAlertInstanceType;
                                    //}

                                    proxy.DescribeDevice(describeDevice);

                                }
                                catch (Exception ex )
                                {
                                    MessageBox.Show(ex.ToString());

                                }
                            }
                            //DescribeDevicePackageType describeDevice = new DescribeDevicePackageType();
                            //describeDevice.DeviceGUID = Convert.ToString(dr["di_AssociationId"]);
                            //DeviceDescriptionType deviceDescriptionType = new DeviceDescriptionType();
                            //deviceDescriptionType.Description = "Test";
                            //deviceDescriptionType.DeviceGUID = Convert.ToString(dr["di_AssociationId"]);
                            //deviceDescriptionType.IPAddress = Convert.ToString(dr["di_IPAddress"]);
                            //deviceDescriptionType.LogicalDeviceID = Convert.ToString(dr["di_LogicalDeviceId"]);
                            //deviceDescriptionType.MACAddress = Convert.ToString(dr["di_MACAddress"]);
                            //deviceDescriptionType.Manufacturer = Convert.ToString(dr["di_Manufacturer"]);
                            //deviceDescriptionType.Model = Convert.ToString(dr["di_Model"]);
                            //deviceDescriptionType.SerialNumber = Convert.ToString(dr["di_SerialNumber"]);
                            //deviceDescriptionType.HostName = Convert.ToString(dr["di_HostName"]);
                            //deviceDescriptionType.SoftwareVersion = Convert.ToString(dr["di_SoftwareVersion"]);
                            //deviceDescriptionType.Type = Convert.ToString(dr["di_DeviceType"]);
                            //describeDevice.DeviceDescription = deviceDescriptionType;
                            //DeviceStatusesType deviceStatusType = new DeviceStatusesType();
                            //deviceStatusType.ServiceStatus = 1;
                            //deviceStatusType.Status = 2;
                            //deviceStatusType.StatusDate = DateTime.Now;
                            //describeDevice.DeviceStatus = deviceStatusType;

                            //proxy.DescribeDevice(describeDevice);
                        }
                    }
                }
            }
            catch (InvalidOperationException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void SendDataExportPackageForPerformance()
        {
            List<DescribeDevicePackageType> _DescribeDevicePackageTypeLst = new List<DescribeDevicePackageType>();
            for (int i = 0; i <= nCurrentRow_DescDevice; i++)
            {
                if (this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_DEVICE_GUID].Value != null &&
                    this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_LOGICAL_ID].Value != null &&
                    this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_DEVICE_TYPE].Value != null &&
                    this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_MANUFACTURER].Value != null &&
                    this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_MODEL].Value != null &&
                    this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_SERIAL_NUMBER].Value != null &&
                    this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_MAC_ADDRESS].Value != null &&
                    this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_IP_ADDRESS].Value != null &&
                    this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_SW_VERSION].Value != null &&
                    !string.IsNullOrEmpty(Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_DEVICE_GUID].Value)) &&
                    !string.IsNullOrEmpty(Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_LOGICAL_ID].Value)) &&
                    !string.IsNullOrEmpty(Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_DEVICE_TYPE].Value)) &&
                    !string.IsNullOrEmpty(Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_MANUFACTURER].Value)) &&
                    !string.IsNullOrEmpty(Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_MODEL].Value)) &&
                    !string.IsNullOrEmpty(Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_SERIAL_NUMBER].Value)) &&
                    !string.IsNullOrEmpty(Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_MAC_ADDRESS].Value)) &&
                    !string.IsNullOrEmpty(Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_SW_VERSION].Value)) &&
                    !string.IsNullOrEmpty(Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_IP_ADDRESS].Value)))
                {
                    DescribeDevicePackageType describeDevice = new DescribeDevicePackageType();
                    describeDevice.DeviceGUID = Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_DEVICE_GUID].Value);
                    DeviceDescriptionType deviceDescriptionType = new DeviceDescriptionType();
                    deviceDescriptionType.Description = "Test";
                    deviceDescriptionType.DeviceGUID = Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_DEVICE_GUID].Value);
                    deviceDescriptionType.IPAddress = Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_IP_ADDRESS].Value);
                    deviceDescriptionType.LogicalDeviceID = Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_LOGICAL_ID].Value);
                    deviceDescriptionType.MACAddress = Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_MAC_ADDRESS].Value);
                    deviceDescriptionType.Manufacturer = Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_MANUFACTURER].Value);
                    deviceDescriptionType.Model = Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_MODEL].Value);
                    deviceDescriptionType.SerialNumber = Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_SERIAL_NUMBER].Value);
                    deviceDescriptionType.HostName = string.Format("Host {0}", deviceDescriptionType.SerialNumber);
                    deviceDescriptionType.SoftwareVersion = Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_SW_VERSION].Value);
                    deviceDescriptionType.Type = Convert.ToString(this.dgvPerformance_DescDevice.Rows[i].Cells[GRD_DEVICE_TYPE].Value);
                    describeDevice.DeviceDescription = deviceDescriptionType;

                    DeviceStatusesType deviceStatusType = new DeviceStatusesType();
                    deviceStatusType.ServiceStatus = 1;
                    deviceStatusType.Status = 2;
                    deviceStatusType.StatusDate = DateTime.Now;

                    describeDevice.DeviceStatus = deviceStatusType;
                    try
                    {
                        _DescribeDevicePackageTypeLst.Add(describeDevice);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                        return;
                    }

                }
            }

            try
            {
                int j = 0;
                foreach (var item in _DescribeDevicePackageTypeLst)
                {
                    j = j + 1;
                    Thread SendDescribeDevicePackageType = new Thread(() => { proxy.DescribeDevice(item); });
                    SendDescribeDevicePackageType.Name = "Thread" + j.ToString();
                    SendDescribeDevicePackageType.Start();
                    System.Threading.Thread.Sleep(20);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            System.Threading.Thread.Sleep(2000);
            _ManualResetEvent.Set();
            System.Threading.Thread.Sleep(2000);
            _ManualResetEvent.Reset();
        }