/// <summary>
        /// Connect To telephony server
        /// </summary>
        /// <param name="telephonyServer"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool Connect(string telephonyServer, string secU, string secP)
        {
            tConnect secConn = new tConnect();

            try
            {
                lock (s_SyncVar)
                {
                    System.Net.IPAddress[] ips = System.Net.Dns.GetHostAddresses(telephonyServer);

                    if (ips == null || ips.Length == 0)
                    {
                        throw new Exception(
                                  "Error: Could not resolve name specified!");
                    }

                    string sIpaddress = @"gtcp://" + ips[0].ToString() + ":54331";
                    Log.Write("|DE|Connecting to Voice Elements server at {0}.", sIpaddress);
                    TelephonyServer          = new TelephonyServer(sIpaddress, secConn.SecU, secConn.SecP);
                    TelephonyServer.NewCall += new NewCall(m_TelephonyServer_NewCall);
                    TelephonyServer.RegisterDNIS();
                    TelephonyServer.SetSingleClientMode();

                    TelephonyServer.AutoAssignVoiceResources = false;

                    Log.Write("CONNECTED");
                    s_Connected = true;

                    try
                    {
                        this.ActivityId = CampaignAPI.DialerConnected();
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message.ToLower().IndexOf("unable to connect to the remote server") >= 0)
                        {
                            Log.Write("|DE|Unable to connect, please check setting and location of the VE server.");
                        }
                        else
                        {
                            Log.Write("|DE|Error connecting to VE server.");
                        }
                        Disconnect();
                        return(false);
                    }
                }
                return(true);
            }
            catch (ElementsException ee)
            {
                TelephonyServer = null;
                Log.WriteException(ee, "Elements Exception Connect");
            }
            catch (Exception ex)
            {
                TelephonyServer = null;
                Log.WriteException(ex, "Exception Connect");
            }
            return(false);
        }
        /// <summary>
        /// Disconnect server
        /// </summary>
        public void Disconnect()
        {
            lock (s_SyncVar)
            {
                s_Connected = false;

                if (TelephonyServer != null)
                {
                    try
                    {
                        // stop campaign polling
                        if (tmrGetCampaigns != null)
                        {
                            tmrGetCampaigns.Stop();
                            tmrGetCampaigns = null;
                        }

                        // stop agents pooling
                        if (tmrGetAgents != null)
                        {
                            tmrGetAgents.Stop();
                            tmrGetAgents = null;
                        }

                        // stop running campaigns
                        StopAllCampaigns();

                        // dispose all channels
                        ManagedChannel.Dispose();
                        ManagedAgent.Dispose();

                        CampaignProcess.Dispose();
                    }
                    catch { }

                    try
                    {
                        CampaignAPI.DialerStoped(this.ActivityId);
                    }
                    catch (Exception ex)
                    {
                        Log.WriteException(ex, "Updating Dialer start error");
                    }

                    TelephonyServer.NewCall -= new NewCall(m_TelephonyServer_NewCall);
                    TelephonyServer.Dispose();
                    TelephonyServer = null;

                    // wait for a while, Child threads release the resources
                    Thread.Sleep(10);
                    Log.Write("|DE|Disconnected from VE server.");
                }
            }
        }