using System; using System.Collections.Generic; using System.Text; namespace Shared.Phone { /// /// 线程逻辑(创建这个东西,是为了Log出力) /// public class HdlThreadLogic { #region ■ 变量声明___________________________ /// /// 线程逻辑(创建这个东西,是为了Log出力) /// private static HdlThreadLogic m_Current = null; /// /// 线程逻辑(创建这个东西,是为了Log出力) /// public static HdlThreadLogic Current { get { if (m_Current == null) { m_Current = new HdlThreadLogic(); } return m_Current; } } #endregion #region ■ 线程执行___________________________ /// /// 子线程执行(创建这个东西,是为了Log出力) /// public void RunThread(Action action, ShowErrorMode mode = ShowErrorMode.YES) { new System.Threading.Thread(() => { //记录起当前界面,虽然似乎没啥用 string nowFormId = HdlFormLogic.Current.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(); } /// /// 执行运行子线程里面的主线程(创建这个东西,是为了Log出力) /// public void RunMainInThread(Action action, ShowErrorMode mode = ShowErrorMode.YES) { new System.Threading.Thread(() => { Application.RunOnMainThread(() => { //记录起当前界面,虽然似乎没啥用 string nowFormId = HdlFormLogic.Current.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(); } /// /// 执行运行于主线程(创建这个东西,是为了Log出力) /// public void RunMain(Action action, ShowErrorMode mode = ShowErrorMode.YES) { Application.RunOnMainThread(() => { //记录起当前界面,虽然似乎没啥用 string nowFormId = HdlFormLogic.Current.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 } }