private static void ZTest()
        {
            string[] channelNames = File.ReadAllLines(@"channels.txt");

            List<EpicsChannel> channels = new List<EpicsChannel>();

            client = new EpicsClient();
            //client.Configuration.SearchAddress = "172.22.200.117:5062";
            //client.Configuration.SearchAddress = "172.22.200.103:5062";
            client.Configuration.WaitTimeout = 2000;

            channelNames = channelNames.OrderBy(a => Guid.NewGuid()).ToArray();

            gotDisconnect = new AutoResetEvent(false);

            foreach (var i in channelNames)
            {
                if (needToStop)
                    break;
                Console.WriteLine("Checking " + i);
                EpicsChannel<ExtControl<string>> c = client.CreateChannel<ExtControl<string>>(i.Trim());
                //EpicsChannel c = client.CreateChannel(i.Trim());
                gotValue = new AutoResetEvent(false);
                c.MonitorChanged += gotValueNotified;
                channels.Add(c);
                /*if (channels.Count > 295)
                    break;*/
                c.StatusChanged += new EpicsStatusDelegate(c_StatusChanged);
                Thread.Sleep(100);
                /*try
                {
                    if (!gotValue.WaitOne(2000))
                    {
                        Console.WriteLine("Never got back.");
                    }
                }
                catch
                {
                    Console.WriteLine("Didn't get value for "+i);
                }
                c.Dispose();
                client.Dispose();*/
            }
            //Console.ReadKey();
            gotDisconnect.WaitOne();
            Console.WriteLine("Nb ok: " + channels.Count);
            Console.WriteLine("Disconnected!");
            client.Dispose();
            Console.ReadKey();
        }
        static void MultiConnect()
        {
            EpicsChannel[] channels = new EpicsChannel[intRecords.Length];

            for (int i = 0; i < channels.Length; i++)
                channels[i] = client.CreateChannel("PCT:INT-" + i);

            client.MultiConnect(channels);
            client.Dispose();

            client = new EpicsClient();
            client.Configuration.SearchAddress = "127.0.0.1:5555";
            for (int i = 0; i < channels.Length; i++)
                channels[i] = client.CreateChannel("PCT:INT-" + i);
            client.MultiConnect(channels);

            Console.WriteLine("Done...");
            Dictionary<uint, string> sids = new Dictionary<uint, string>();
            foreach (EpicsChannel c in channels)
            {
                if (sids.ContainsKey(c.SID) && sids[c.SID] != c.ChannelName)
                {
                    Console.WriteLine("Reuse: " + c.SID);
                }
                else if (!sids.ContainsKey(c.SID))
                    sids.Add(c.SID, c.ChannelName);
            }

            client.Dispose();
        }
        private static void QuickMonitor()
        {
            gateway = new Gateway();
            gateway.Configuration.GatewayName = "TESTGW";
            gateway.Configuration.LocalAddressSideA = "127.0.0.1:5432";
            //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
            gateway.Configuration.RemoteAddressSideA = "127.0.0.1:5552";
            gateway.Configuration.LocalAddressSideB = "129.129.130.87:5064";
            //gateway.Configuration.LocalAddressSideB = "172.22.200.116:5432";
            //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
            //gateway.Configuration.RemoteAddressSideB = "172.22.255.255:5064";
            gateway.Configuration.RemoteAddressSideB = "172.22.200.117:5062";
            gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
            gateway.SaveConfig();
            gateway.Start();

            Thread.Sleep(1000);

            EpicsClient client = new EpicsClient();
            string clientConfig = "127.0.0.1:5432";
            //string clientConfig="172.22.100.101:5064";
            client.Configuration.SearchAddress = clientConfig;

            //string[] channelNames = { "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL", "ZPSAF101-VME:CALNCONN.EGU", "ZPSAF101-VME:CALDCONN.EGU", "ZPSAF101-VME:LOAD", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:HBT" };
            //string[] channelNames = { "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CALNCONN.EGU", "ZPSAF101-VME:CALDCONN.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU" };
            string[] channelNames = { "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CALNCONN.EGU", "ZPSAF101-VME:CALDCONN.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:HBT.EGU", "ZPSAF101-VME:HBT.EGU", "ZPSAF101-VME:LOAD.EGU" };
            //string[] channelNames = { "ZPSAF101-VME:CAL.EGU" };
            while (true)
            {
                for (int l = 0; l < 10; l++)
                {
                    List<EpicsChannel<ExtGraphic<string>>> channels = new List<EpicsChannel<ExtGraphic<string>>>();
                    foreach (var i in channelNames)
                    {
                        EpicsChannel<ExtGraphic<string>> c = client.CreateChannel<ExtGraphic<string>>(i);
                        c.MonitorChanged += new EpicsDelegate<ExtGraphic<string>>(QuickMonitor);
                        channels.Add(c);
                    }
                    foreach (var i in channels)
                        i.Dispose();
                    client.Dispose();
                    client = new EpicsClient();
                    client.Configuration.SearchAddress = clientConfig;
                }

                if (true)
                {
                    bool gotError = false;
                    List<EpicsChannel<ExtGraphic<string>>> channels = new List<EpicsChannel<ExtGraphic<string>>>();
                    foreach (var i in channelNames)
                    {
                        EpicsChannel<ExtGraphic<string>> c = client.CreateChannel<ExtGraphic<string>>(i);
                        channels.Add(c);
                    }

                    CountdownEvent multiActionCountDown = new CountdownEvent(channelNames.Count());
                    Dictionary<uint, bool> gotMonitor = new Dictionary<uint, bool>();

                    foreach (EpicsChannel<ExtGraphic<string>> c in channels)
                    {
                        c.MonitorChanged += delegate(EpicsChannel<ExtGraphic<string>> sender, ExtGraphic<string> newValue)
                        {
                            if ((newValue.Value != "#" && sender.ChannelName.Contains(":CAL")) ||
                                (newValue.Value != "%" && sender.ChannelName.Contains(":LOAD")) ||
                                (newValue.Value != "ticks" && sender.ChannelName.Contains(":HBT")))
                            {
                                Console.WriteLine("Wrong data on CID (" + sender.ChannelName + "): " + sender.CID + ", " + newValue.Value);
                                gotError = true;
                            }
                            lock (gotMonitor)
                            {
                                if (!gotMonitor.ContainsKey(sender.CID))
                                {
                                    gotMonitor.Add(sender.CID, true);
                                    multiActionCountDown.Signal();
                                }
                            }
                        };

                        c.MonitorChanged += new EpicsDelegate<ExtGraphic<string>>(QuickMonitor);
                    }

                    multiActionCountDown.Wait(2500);

                    bool allConnected = true;
                    foreach (var i in channels)
                    {
                        if (i.Status != ChannelStatus.CONNECTED)
                        {
                            allConnected = false;
                            Console.WriteLine(i.ChannelName + " not connected.");
                            //gotError = true;
                        }
                    }

                    if (!allConnected)
                    {
                        needToShow = false;
                        //gotError = true;
                        Console.WriteLine("Not all connected!!!!!");
                    }

                    foreach (var i in channels)
                        i.Dispose();
                    client.Dispose();
                    client = new EpicsClient();
                    client.Configuration.SearchAddress = clientConfig;
                    multiActionCountDown.Dispose();

                    if (gotError)
                    {
                        Console.Beep();
                        Console.WriteLine("Press any key to continue...");
                        Console.ReadKey();
                        needToShow = true;
                    }
                }
            }
        }
        static void MonAll()
        {
            //PBCaGw.Services.Log.Enabled = false;
            Stopwatch sw = new Stopwatch();
            for (int loop = 0; loop < 10; loop++)
            {
                gateway = new Gateway();
                gateway.Configuration.GatewayName = "TESTGW";
                gateway.Configuration.LocalAddressSideA = ip + ":5555";
                //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
                gateway.Configuration.RemoteAddressSideA = remoteIp + ":5552";
                gateway.Configuration.LocalAddressSideB = ip + ":5888";
                //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
                gateway.Configuration.RemoteAddressSideB = "172.25.60.67:5062";
                gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
                gateway.SaveConfig();
                gateway.Start();

                Console.WriteLine("Gateway up");
                //gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.BIDIRECTIONAL;

                Gateway.BufferedSockets = false;

                Thread.Sleep(1000);
                multiActionCountDown = new CountdownEvent(channelsToConnect.Count(row => !row.Contains("TRACE")));
                hadValue = new Dictionary<string, bool>();
                sw.Start();
                client = new EpicsClient();
                client.Configuration.WaitTimeout = 2000;
                client.Configuration.SearchAddress = ip + ":5555";
                List<EpicsChannel<ExtGraphic<string>>> channels = new List<EpicsChannel<ExtGraphic<string>>>();
                foreach (string i in channelsToConnect.Where(row => !row.Contains("TRACE")))
                {
                    EpicsChannel<ExtGraphic<string>> ch = client.CreateChannel<ExtGraphic<string>>(i);
                    ch.MonitorChanged += new EpicsDelegate<ExtGraphic<string>>(ch_MonitorChangedGotValue);
                    channels.Add(ch);
                }
                if (multiActionCountDown.Wait(5000) == false)
                    Console.WriteLine("Didn't got it...");
                client.Dispose();
                sw.Stop();
                gateway.Dispose();
            }

            Console.WriteLine("Time: " + sw.Elapsed.ToString());
            Console.ReadKey();
        }