/// <summary> /// 与环信服务器断开连接 /// </summary> /// <param name="error"></param> private void onDisconnect(EMError error) { ThreadPool.QueueUserWorkItem((o) => { Console.WriteLine("em----------------------------------------Discont"); if (error.errorCode == EMErrorCode.SERVER_UNKNOWN_ERROR) { EMError err = client.login(SettingMenager.shard.userID, SettingMenager.shard.userID); if (err.errorCode == EMErrorCode.EM_NO_ERROR) { } else { MainFrm main = (MainFrm)Application.OpenForms["MainFrm"]; if (main == null) { if (relogin) { return; } relogin = true; MessageBox.Show("未知错误,请重新登录"); return; } else { if (relogin) { return; } relogin = true; main.BeginInvoke(new EventHandler((s, e) => { MessageBox.Show("未知错误,请重新登录"); })); } } } }); }
private void searchPerson() { if (string.IsNullOrEmpty(dSkinTextBox1.Text)) { MessageBox.Show("请填写手机号或者畅聊号"); return; } GetUserByMobileOrIdCardSendModel model = new GetUserByMobileOrIdCardSendModel(); model.mobile = dSkinTextBox1.Text; HttpUitls.Instance.get <GetUserByMobileOrIdCardReciveModel>("user/getUserByMobile", model, (json) => { if (json.code == 200) { FriendListData friend = DBHelper.Instance.getFriend(json.data.user_id); if (friend == null) { MainFrm frm = Application.OpenForms["MainFrm"] as MainFrm; if (frm != null) { GetUserData data = new GetUserData(); data.user_id = json.data.user_id; data.user_name = json.data.user_name; data.portrait = json.data.portrait; data.id_card = json.data.id_card; UserInfoForm form = new UserInfoForm(data); frm.BeginInvoke(new EventHandler((s, e) => { this.FormClosed += new FormClosedEventHandler((ss, ee) => { form.BeginInvoke(new EventHandler((sss, sse) => { form.BringToFront(); form.Activate(); })); }); this.Close(); form.Show(); })); DBHelper.Instance.addStronger(data); } else { this.BeginInvoke(new EventHandler((s, e) => { GetUserData data = new GetUserData(); data.user_id = json.data.user_id; data.user_name = json.data.user_name; data.portrait = json.data.portrait; data.id_card = json.data.id_card; UserInfoForm form = new UserInfoForm(data); form.Show(); DBHelper.Instance.addStronger(data); this.Close(); form.BringToFront(); })); } } else { MainFrm frm = Application.OpenForms["MainFrm"] as MainFrm; if (frm != null) { UserInfoForm form = new UserInfoForm(friend.toFriend()); frm.BeginInvoke(new EventHandler((s, e) => { this.FormClosed += new FormClosedEventHandler((ss, ee) => { form.BeginInvoke(new EventHandler((sss, sse) => { form.BringToFront(); form.Activate(); })); }); this.Close(); form.Show(); })); GetUserData data = new GetUserData(); data.user_id = json.data.user_id; data.user_name = json.data.user_name; data.portrait = json.data.portrait; data.id_card = json.data.id_card; DBHelper.Instance.addStronger(data); } else { this.BeginInvoke(new EventHandler((s, e) => { UserInfoForm form = new UserInfoForm(friend.toFriend()); form.Show(); GetUserData data = new GetUserData(); data.user_id = json.data.user_id; data.user_name = json.data.user_name; data.portrait = json.data.portrait; data.id_card = json.data.id_card; DBHelper.Instance.addStronger(data); this.Close(); form.BringToFront(); })); } } } else { this.BeginInvoke(new EventHandler((s, ee) => { MessageBox.Show(json.message); })); if (json.message.Contains("请重新登录")) { MainFrm frm = (MainFrm)Application.OpenForms["MainFrm"]; if (frm != null) { frm.gotoLogin(); this.BeginInvoke(new EventHandler((s, ee) => { this.Close(); })); } } } }, (code) => { if (code > 500 && code < 503) { this.BeginInvoke(new EventHandler((s, ee) => { MessageBox.Show("请重新登录"); })); MainFrm frm = (MainFrm)Application.OpenForms["MainFrm"]; if (frm != null) { frm.gotoLogin(); this.BeginInvoke(new EventHandler((s, ee) => { this.Close(); })); } } }); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var config = new NLog.Config.LoggingConfiguration(); // Targets where to log to: File and Console var logfile = new NLog.Targets.FileTarget("logfile") { FileName = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Changliao", "err.log") }; // Rules for mapping loggers to targets config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile); // Apply config NLog.LogManager.Configuration = config; new Thread(new ThreadStart(() => { _ = EmotionManager.shard; })).Start(); new Thread(new ThreadStart(() => { BaseSendModel m = new BaseSendModel(); m.type = 4; HttpUitls.Instance.get <GetVersionReciveModel>("common/getVersion", m, (json) => { if (json.code == 200) { if (json.data == null) { return; } double newversion = Convert.ToDouble(json.data.newVersion); double oldversion = Convert.ToDouble(Properties.Settings.Default.version); if (newversion > oldversion) { if (json.data != null) { if (json.data.is_forced == 1) { LoginForm loginForm = Application.OpenForms["LoginForm"] as LoginForm; if (loginForm != null) { loginForm.BeginInvoke(new EventHandler((s, e) => { loginForm.Close(); })); Thread t = new Thread(new ThreadStart(() => { UpdateForm frm = new UpdateForm(json.data.apkUrl); Application.Run(frm); })); t.SetApartmentState(ApartmentState.STA); t.Start(); } MainFrm main = Application.OpenForms["MainFrm"] as MainFrm; if (main != null) { main.BeginInvoke(new EventHandler((s, e) => { main.Close(); })); Thread t = new Thread(new ThreadStart(() => { UpdateForm frm = new UpdateForm(json.data.apkUrl); Application.Run(frm); })); t.SetApartmentState(ApartmentState.STA); t.Start(); } } else { if (MessageBox.Show("发现新版本,是否升级?", "版本更新", MessageBoxButtons.OKCancel) == DialogResult.OK) { LoginForm loginForm = Application.OpenForms["LoginForm"] as LoginForm; if (loginForm != null) { loginForm.BeginInvoke(new EventHandler((s, e) => { loginForm.Close(); })); Thread t = new Thread(new ThreadStart(() => { UpdateForm frm = new UpdateForm(json.data.apkUrl); Application.Run(frm); })); t.SetApartmentState(ApartmentState.STA); t.Start(); } MainFrm main = Application.OpenForms["MainFrm"] as MainFrm; if (main != null) { main.BeginInvoke(new EventHandler((s, e) => { main.Close(); })); Thread t = new Thread(new ThreadStart(() => { UpdateForm frm = new UpdateForm(json.data.apkUrl); Application.Run(frm); })); t.SetApartmentState(ApartmentState.STA); t.Start(); } } } } } } }, (code) => { }); })).Start(); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.Automatic); Application.ThreadException += Application_ThreadException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.Run(new LoginForm()); }