From 25429f085093d89d543a0b90e30d0d62d1b7dac9 Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期二, 30 八月 2022 09:37:38 +0800 Subject: [PATCH] 合并了IOS的代码 --- ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlThreadLogic.cs | 141 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 141 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlThreadLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlThreadLogic.cs new file mode 100644 index 0000000..38f98af --- /dev/null +++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlThreadLogic.cs @@ -0,0 +1,141 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Text; + +namespace Shared.Phone.UserCenter +{ + /// <summary> + /// 绾跨▼閫昏緫(鍒涘缓杩欎釜涓滆タ,鏄负浜哃og鍑哄姏) + /// </summary> + public class HdlThreadLogic + { + #region 鈻� 鍙橀噺澹版槑___________________________ + + /// <summary> + /// 绾跨▼閫昏緫(鍒涘缓杩欎釜涓滆タ,鏄负浜哃og鍑哄姏) + /// </summary> + private static HdlThreadLogic m_Current = null; + /// <summary> + /// 绾跨▼閫昏緫(鍒涘缓杩欎釜涓滆タ,鏄负浜哃og鍑哄姏) + /// </summary> + public static HdlThreadLogic Current + { + get + { + if (m_Current == null) + { + m_Current = new HdlThreadLogic(); + } + return m_Current; + } + } + #endregion + + #region 鈻� 绾跨▼鎵ц___________________________ + + /// <summary> + /// 瀛愮嚎绋嬫墽琛�(鍒涘缓杩欎釜涓滆タ,鏄负浜哃og鍑哄姏) + /// </summary> + public void RunThread(Action action, ShowErrorMode mode = ShowErrorMode.YES) + { + new System.Threading.Thread(() => + { + //璁板綍璧峰綋鍓嶇晫闈紝铏界劧浼间箮娌″暐鐢� + string nowFormId = UserCenterResourse.NowActionFormID; + try + { + action.Invoke(); + action = null; + } + catch (Exception ex) + { + if (mode == ShowErrorMode.YES) + { + Application.RunOnMainThread(() => + { + //鍑虹幇鏈煡閿欒,鏁版嵁涓㈠け + var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError)); + alert.Show(); + //鍑虹幇寮傚父,鍒欏叧闂繘搴︽潯 + ProgressBar.Close(); + }); + } + //Log鍑哄姏 + string msg = "褰撳墠婵�娲荤殑鐣岄潰[" + nowFormId + "]"; + HdlLogLogic.Current.WriteLog(ex, msg); + } + }) + { IsBackground = true }.Start(); + } + + /// <summary> + /// 鎵ц杩愯瀛愮嚎绋嬮噷闈㈢殑涓荤嚎绋�(鍒涘缓杩欎釜涓滆タ,鏄负浜哃og鍑哄姏) + /// </summary> + public void RunMainInThread(Action action, ShowErrorMode mode = ShowErrorMode.YES) + { + new System.Threading.Thread(() => + { + Application.RunOnMainThread(() => + { + //璁板綍璧峰綋鍓嶇晫闈紝铏界劧浼间箮娌″暐鐢� + string nowFormId = UserCenterResourse.NowActionFormID; + try + { + action.Invoke(); + action = null; + } + catch (Exception ex) + { + if (mode == ShowErrorMode.YES) + { + //鍑虹幇鏈煡閿欒,鏁版嵁涓㈠け + var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError)); + alert.Show(); + } + //Log鍑哄姏 + string msg = "褰撳墠婵�娲荤殑鐣岄潰[" + nowFormId + "]"; + HdlLogLogic.Current.WriteLog(ex, msg); + //鍑虹幇寮傚父,鍒欏叧闂繘搴︽潯 + ProgressBar.Close(); + } + }); + + }) + { IsBackground = true }.Start(); + } + + /// <summary> + /// 鎵ц杩愯浜庝富绾跨▼(鍒涘缓杩欎釜涓滆タ,鏄负浜哃og鍑哄姏) + /// </summary> + public void RunMain(Action action, ShowErrorMode mode = ShowErrorMode.YES) + { + Application.RunOnMainThread(() => + { + //璁板綍璧峰綋鍓嶇晫闈紝铏界劧浼间箮娌″暐鐢� + string nowFormId = UserCenterResourse.NowActionFormID; + try + { + action.Invoke(); + action = null; + } + catch (Exception ex) + { + if (mode == ShowErrorMode.YES) + { + //鍑虹幇鏈煡閿欒,鏁版嵁涓㈠け + var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError)); + alert.Show(); + } + + //Log鍑哄姏 + string msg = "褰撳墠婵�娲荤殑鐣岄潰[" + nowFormId + "]"; + HdlLogLogic.Current.WriteLog(ex, msg); + //鍑虹幇寮傚父,鍒欏叧闂繘搴︽潯 + ProgressBar.Close(); + } + }); + } + + #endregion + } +} -- Gitblit v1.8.0