private async void start_server_Click(object sender, RoutedEventArgs e) //サーバ開始ボタン
        {
            start_server.IsEnabled = false;

            /*
             * if(tcp == null)
             * {
             *  int port = int.Parse(port_textbox.Text);
             *  tcp = new tcp_conection("0,0,0,0", port);
             *  status_label.Content = "サーバ待機";
             *  await Task.Run(() => listen());
             *
             * }
             */

            password               = password_textbox.Text;
            port                   = int.Parse(port_textbox.Text);       //数字以外の数が入ってきたら例外になるので例外処理書かないと
            tcp                    = new tcp_conection("0,0,0,0", port); //サーバ側なので第一引数はどうでもいい
            status_label.Content   = "サーバ待機";
            port_textbox.IsEnabled = false;
            await Task.Run(() => listen()); //runlisten()メソッドでもいいのでは?
        }
        private void listen()
        {
            status_label.Dispatcher.BeginInvoke(
                    new Action(() =>
                    {
                        status_label.Content = "サーバ待機";
                        statusbar.Background = getBrushColor(202, 81, 0, 255);
                        BorderBrush = getBrushColor(202, 81, 0, 255);
                    })
                );

            tcp.listen();

            /*
            string str;
            str = string.Format("{0},{1},0", per.cpu_count(), per.max_mem());
            System.Console.WriteLine(str);

            tcp.send(str);

            */

            bool ok = false;

            while (!ok)
            {
                string tcp_str = tcp.recive();
                if (tcp_str != "0") {
                    if (tcp_str == password)
                    {
                        ok = true;
                        tcp.connection = true;  //tcp.connectionを違うインスタンスからいじるのはよくない気がする、どうにかしたいね
                        System.Console.WriteLine("準備完了");

                        status_label.Dispatcher.BeginInvoke(
                              new Action(() =>
                              {
                                status_label.Content = "接続完了";
                                statusbar.Background = getBrushColor(104, 33, 122, 255);
                                BorderBrush = getBrushColor(104, 33, 122, 255);
                                client_label.Content = tcp.get_client_IP();
                                client_label.Foreground = getBrushColor(45, 133, 193, 255);
                                })
                        );

                        string str;
                        str = string.Format("{0},{1},0", per.cpu_count(), per.max_mem());
                        System.Console.WriteLine(str);

                        tcp.send(str);
                    }
                    else //パスワード間違えるとだんだんCPU使用率が上がっていく
                    {
                        tcp.send("password_error");
                        
                        tcp.disconnection();

                        tcp = new tcp_conection("0,0,0,0", port);

                        this.Dispatcher.BeginInvoke(
                            new Action(() =>
                            {
                                listen();
                            })
                            );
                    }
                }
            }

            /*
            status_label.Dispatcher.BeginInvoke(
                    new Action(() =>
                    {
                        status_label.Content = "接続完了";
                        statusbar.Background = getBrushColor(104, 33, 122, 255);
                        BorderBrush = getBrushColor(104, 33, 122, 255);
                        client_label.Content = tcp.get_client_IP();
                        client_label.Foreground = getBrushColor(45,133,193,255);
                    })
                );
                */
        }
        private async void start_server_Click(object sender, RoutedEventArgs e) //サーバ開始ボタン
        {
            start_server.IsEnabled = false;

            /*
            if(tcp == null)
            {
                int port = int.Parse(port_textbox.Text);
                tcp = new tcp_conection("0,0,0,0", port);
                status_label.Content = "サーバ待機";
                await Task.Run(() => listen());

            }
            */

            password = password_textbox.Text;
            port = int.Parse(port_textbox.Text);    //数字以外の数が入ってきたら例外になるので例外処理書かないと
            tcp = new tcp_conection("0,0,0,0", port);   //サーバ側なので第一引数はどうでもいい
            status_label.Content = "サーバ待機";
            port_textbox.IsEnabled = false;
            await Task.Run(() => listen()); //runlisten()メソッドでもいいのでは?
        }
        private void tick()
        {
            while(tick_switch)
            {
                System.Console.WriteLine("Tick");

                int mem = per.get_use_mem();
                int cpu = per.get_all_cpu();

                CPU_label.Dispatcher.BeginInvoke(
                        new Action(() =>
                        {
                            CPU_label.Content = string.Format("{0}%",cpu);
                            mem_label.Content = string.Format("{0}MB", mem);
                        })
                        );

                if (tcp != null)
                {
                    if (tcp.connection) //クライアントが接続していたら
                    {
                        System.Console.WriteLine("sendsend!!!");
                        string sendstr;
                        //tcp.send(sendstr);
                        //System.Console.WriteLine("send:{0}",sendstr);

                        sendstr = string.Format("{0},{1}", mem, cpu);
                        //sendstr = string.Format("{0},{1}", 4000, 90);
                        for (int i = 0; i < per.cpu_count(); i++)
                        {
                            string str = string.Format(",{0}", per.get_thread_cpu(i));
                            sendstr += str;
                        }

                        sendstr += ",0";
                        int result = tcp.send(sendstr);
                        System.Console.WriteLine("send:{0}", sendstr);

                        if (result == 101)
                        {
                            tcp.disconnection();
                            
                            /*
                            start_server.Dispatcher.BeginInvoke(
                                 new Action(() =>
                                 {
                                     start_server.IsEnabled = true;
                                     status_label.Content = "未接続";
                                     statusbar.Background = getBrushColor(45, 133, 193, 255);
                                     BorderBrush = getBrushColor(45,133,193, 255);
                                 })
                                );
                            */ 
                            //↑はクライアントが切断したらまたサーバ開始ボタン押さないといけない

                            //↓はクライアントが切断したらlistenを自動的に開始して何もしなくてもクライアントが接続できるようにしてる
                            
                            status_label.Dispatcher.BeginInvoke(
                                new Action(()=>
                                {
                                    status_label.Content = "サーバ待機";
                                    client_label.Foreground = getBrushColor(255,123,123,255);
                                    client_label.Content = "クライアントなし";

                                    //statusbar.Background = getBrushColor(202, 81, 0, 255);
                                    //BorderBrush = getBrushColor(202, 81, 0, 255);
                                })
                                );
                            tcp = new tcp_conection("0,0,0,0", port);
                            runlisten(); //await Task.Run(() => listen());ってしたかった
                            

                        }
                    }
                }

                System.Threading.Thread.Sleep(1000);
            }
        }
        private void listen()
        {
            status_label.Dispatcher.BeginInvoke(
                new Action(() =>
            {
                status_label.Content = "サーバ待機";
                statusbar.Background = getBrushColor(202, 81, 0, 255);
                BorderBrush          = getBrushColor(202, 81, 0, 255);
            })
                );

            tcp.listen();

            /*
             * string str;
             * str = string.Format("{0},{1},0", per.cpu_count(), per.max_mem());
             * System.Console.WriteLine(str);
             *
             * tcp.send(str);
             *
             */

            bool ok = false;

            while (!ok)
            {
                string tcp_str = tcp.recive();
                if (tcp_str != "0")
                {
                    if (tcp_str == password)
                    {
                        ok             = true;
                        tcp.connection = true;  //tcp.connectionを違うインスタンスからいじるのはよくない気がする、どうにかしたいね
                        System.Console.WriteLine("準備完了");

                        status_label.Dispatcher.BeginInvoke(
                            new Action(() =>
                        {
                            status_label.Content    = "接続完了";
                            statusbar.Background    = getBrushColor(104, 33, 122, 255);
                            BorderBrush             = getBrushColor(104, 33, 122, 255);
                            client_label.Content    = tcp.get_client_IP();
                            client_label.Foreground = getBrushColor(45, 133, 193, 255);
                        })
                            );

                        string str;
                        str = string.Format("{0},{1},0", per.cpu_count(), per.max_mem());
                        System.Console.WriteLine(str);

                        tcp.send(str);
                    }
                    else //パスワード間違えるとだんだんCPU使用率が上がっていく
                    {
                        tcp.send("password_error");

                        tcp.disconnection();

                        tcp = new tcp_conection("0,0,0,0", port);

                        this.Dispatcher.BeginInvoke(
                            new Action(() =>
                        {
                            listen();
                        })
                            );
                    }
                }
            }

            /*
             * status_label.Dispatcher.BeginInvoke(
             *      new Action(() =>
             *      {
             *          status_label.Content = "接続完了";
             *          statusbar.Background = getBrushColor(104, 33, 122, 255);
             *          BorderBrush = getBrushColor(104, 33, 122, 255);
             *          client_label.Content = tcp.get_client_IP();
             *          client_label.Foreground = getBrushColor(45,133,193,255);
             *      })
             *  );
             */
        }
        private void tick()
        {
            while (tick_switch)
            {
                System.Console.WriteLine("Tick");

                int mem = per.get_use_mem();
                int cpu = per.get_all_cpu();

                CPU_label.Dispatcher.BeginInvoke(
                    new Action(() =>
                {
                    CPU_label.Content = string.Format("{0}%", cpu);
                    mem_label.Content = string.Format("{0}MB", mem);
                })
                    );

                if (tcp != null)
                {
                    if (tcp.connection) //クライアントが接続していたら
                    {
                        System.Console.WriteLine("sendsend!!!");
                        string sendstr;
                        //tcp.send(sendstr);
                        //System.Console.WriteLine("send:{0}",sendstr);

                        sendstr = string.Format("{0},{1}", mem, cpu);
                        //sendstr = string.Format("{0},{1}", 4000, 90);
                        for (int i = 0; i < per.cpu_count(); i++)
                        {
                            string str = string.Format(",{0}", per.get_thread_cpu(i));
                            sendstr += str;
                        }

                        sendstr += ",0";
                        int result = tcp.send(sendstr);
                        System.Console.WriteLine("send:{0}", sendstr);

                        if (result == 101)
                        {
                            tcp.disconnection();

                            /*
                             * start_server.Dispatcher.BeginInvoke(
                             *   new Action(() =>
                             *   {
                             *       start_server.IsEnabled = true;
                             *       status_label.Content = "未接続";
                             *       statusbar.Background = getBrushColor(45, 133, 193, 255);
                             *       BorderBrush = getBrushColor(45,133,193, 255);
                             *   })
                             *  );
                             */
                            //↑はクライアントが切断したらまたサーバ開始ボタン押さないといけない

                            //↓はクライアントが切断したらlistenを自動的に開始して何もしなくてもクライアントが接続できるようにしてる

                            status_label.Dispatcher.BeginInvoke(
                                new Action(() =>
                            {
                                status_label.Content    = "サーバ待機";
                                client_label.Foreground = getBrushColor(255, 123, 123, 255);
                                client_label.Content    = "クライアントなし";

                                //statusbar.Background = getBrushColor(202, 81, 0, 255);
                                //BorderBrush = getBrushColor(202, 81, 0, 255);
                            })
                                );
                            tcp = new tcp_conection("0,0,0,0", port);
                            runlisten();  //await Task.Run(() => listen());ってしたかった
                        }
                    }
                }

                System.Threading.Thread.Sleep(1000);
            }
        }