コード例 #1
0
        private void FindServer()
        {
            Thread th = new Thread(() =>
            {
                try
                {
                    AutoResetEvent myEvent = new AutoResetEvent(false);

                    StringBuilder ls_ip = new StringBuilder(1024);
                    IvyGetValue.GetIP(ls_ip);
                    int ll_len = IvyGetValue.F_0001_0016(ls_ip);
                    StringBuilder ls_computers = new StringBuilder(ll_len);
                    IvyGetValue.F_0001_0017(ls_computers); //返回 ip + (tab) + 机器名,多部机分多行
                    ips = ls_computers.ToString().Split(',');

                    foreach (string ip in ips)
                    {
                        IBLL.ICommonBLL bll = new BLL.CommonBLL();
                        string isServer     = bll.IsServer(ips[cycleIndex], "8383");

                        if (isServer.Equals("1"))
                        {
                            //成功
                            Helper.Appsetting.ip   = ips[cycleIndex];
                            Helper.Appsetting.port = "8383";

                            this.Invoke((MethodInvoker) delegate
                            {
                                this.Close();
                            });
                        }
                    }
                }
                catch (Exception e)
                {
                    Helper.LogHelper.writeLog("findServer", e.ToString());
                    MsgForm.ShowFrom(e);
                    Application.Exit();
                }
            });

            th.IsBackground = true;
            th.Start();
        }