更新界面通用方法:
#region 是否正在导出 /// <summary>正在工作 </summary> bool IsWorking { get { return isWorking; } set { ChangeControlEnabled(!value); isWorking = value; } } #endregion
#region UI /// <summary> /// 更新界面 /// </summary> /// <param name="action"></param> private void UpdateUIInThread(Action action) { if (this.Disposing || this.IsDisposed) return; if (this.InvokeRequired) this.Invoke(action); else action(); } /// <summary> /// 启用/禁用界面操作 /// </summary> /// <param name="enabled"></param> private void ChangeControlEnabled(bool enabled) { UpdateUIInThread(() => { BtnOpenFile.Enabled = enabled; TxtfoldPath.Enabled = enabled; TxtHostIP.Enabled = enabled; TxtAccount.Enabled = enabled; TxtPwd.Enabled = enabled; TxtServer.Enabled = enabled; BtnSave.Enabled = enabled; BtnStop.Enabled = false; BtnExport.Enabled = !Rd_Server.Checked; DatePick_backupTime.Enabled = enabled; Num_day.Enabled = enabled; CheckBox_Full.Enabled = enabled; CheckBox_Grants.Enabled = enabled; }); } #endregion