private void StartServer()
        {
            try
            {
                _serverRunning = !_serverRunning;
                if (_serverRunning)
                {
                    host = new ServiceHost(new Ampelsteuerung(), new Uri[] { new Uri("net.pipe://localhost") });
                    host.AddServiceEndpoint(typeof(IAmpelService), new NetNamedPipeBinding(), "Ampelsteuerung");
                    host.Open();
                    Ampelsteuerung Ampel = new Ampelsteuerung();


                    while (getAmpelAnzahl() == 0)
                    {
                    }

                    if (getAmpelAnzahl() != 0)
                    {
                        Trafficlights       = Ampel.factory(getAmpelAnzahl());
                        run                 = true;
                        Ampeltimer          = new Timer(1000);
                        Ampeltimer.Elapsed += (sender, e) => HandleTimer();
                        Ampeltimer.Enabled  = true;
                    }
                    while (run)
                    {
                    }
                }
                else
                {
                    host.Close();
                    host = null;
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
        private void StartServer()
        {
            try
            {
                _serverRunning = !_serverRunning;

                if (_serverRunning)
                {
                    host = new ServiceHost(new Ampelsteuerung(), new Uri[] { new Uri("net.pipe://localhost") });
                    host.AddServiceEndpoint(typeof(IAmpelService), new NetNamedPipeBinding(), "Ampelsteuerung");
                    host.Open();

                    Console.WriteLine("Server ist gestartet!!");

                    Ampelsteuerung Ampel = new Ampelsteuerung();

                    while (getAmpelAnzahl() == 0)
                    {
                    }

                    Trafficlights = Ampel.factory(getAmpelAnzahl());

                    while (true)
                    {
                        int Status = 0;
                        for (int i = 0; i < Trafficlights.Count; i++)
                        {
                            Trafficlights.ElementAt(i).getStatus();
                            if (Trafficlights.ElementAt(i).getStatus() >= 2)
                            {
                                if (Trafficlights.ElementAt(i).getDefect() == false)
                                {
                                    Status = Trafficlights.ElementAt(i).setStatus(0);
                                }
                                else
                                {
                                    Status = Trafficlights.ElementAt(i).setStatus(3);
                                }
                            }
                            else
                            {
                                Status = Trafficlights.ElementAt(i).setStatus(Trafficlights.ElementAt(i).getStatus() + 1);
                            }
                            if (Status == 0)
                            {
                                Thread.Sleep(Trafficlights.ElementAt(i).getRotPhase() * 1000);
                            }
                            else if (Status == 1)
                            {
                                Thread.Sleep(Trafficlights.ElementAt(i).getGelbPhase() * 1000);
                            }
                            else if (Status == 2 || Status == 3)
                            {
                                Thread.Sleep(Trafficlights.ElementAt(i).getGruenPhase() * 1000);
                            }
                        }
                    }
                }
                else
                {
                    host.Close();
                    host = null;
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
        static void Main()
        {
            Ampelsteuerung test = new Ampelsteuerung();

            test.StartServer();
        }