private bool ValidateCNCSerialNo(string machineId, string ipAddress, ushort port, List <string> cncSerialnumbers, out bool isLicCheckedSucessfully, out string cncID)
        {
            bool result = false;

            isLicCheckedSucessfully = true;
            Ping   ping           = null;
            ushort focasLibHandle = 0;

            cncID = string.Empty;

            try
            {
                ping = new Ping();
                PingReply pingReply = null;
                while (true)
                {
                    pingReply = ping.Send(ipAddress, 10000);
                    if (pingReply.Status != IPStatus.Success)
                    {
                        if (ServiceStop.stop_service == 1)
                        {
                            break;
                        }
                        Logger.WriteErrorLog("Not able to ping. Ping status = " + pingReply.Status.ToString());
                        Thread.Sleep(10000);
                    }
                    else if (pingReply.Status == IPStatus.Success || ServiceStop.stop_service == 1)
                    {
                        break;
                    }
                }
                if (pingReply.Status == IPStatus.Success)
                {
                    int num2 = FocasData.cnc_allclibhndl3(ipAddress, port, 10, out focasLibHandle);
                    if (num2 == 0)
                    {
                        string text = FocasData.ReadCNCId(focasLibHandle);
                        if (!string.IsNullOrEmpty(text))
                        {
                            if (cncSerialnumbers.Contains(text))
                            {
                                cncID  = text;
                                result = true;
                            }
                        }
                        else
                        {
                            isLicCheckedSucessfully = false;
                        }
                    }
                    else
                    {
                        Logger.WriteErrorLog("Not able to connect to machine. cnc_allclibhndl3 status = " + num2.ToString());
                        isLicCheckedSucessfully = false;
                    }
                }
                else
                {
                    Logger.WriteErrorLog("Not able to ping. Ping status = " + pingReply.Status.ToString());
                    isLicCheckedSucessfully = false;
                }
            }
            catch (Exception ex)
            {
                isLicCheckedSucessfully = false;
                Logger.WriteDebugLog(ex.ToString());
            }
            finally
            {
                if (ping != null)
                {
                    ping.Dispose();
                }
                if (focasLibHandle != 0)
                {
                    short num3 = FocasData.cnc_freelibhndl(focasLibHandle);
                    //if (num3 != 0) _focasHandles.Add(focasLibHandle);
                }
            }
            return(result);
        }