private string requestValueFromUI(Int16 index) { if (!timetoClose) { switch (index) { case 0: if (dlRuleCBox.InvokeRequired) { string getted = ""; var tasktoInvoke = new Action(() => getted = Convert.ToString(dlRuleCBox.SelectedIndex)); dlRuleCBox.Invoke(tasktoInvoke); return(getted); } else { return(Convert.ToString(dlRuleCBox.SelectedIndex)); } break; case 1: if (dlRuleCBox.InvokeRequired) { string getted = ""; var tasktoInvoke = new Action(() => getted = Convert.ToString(dlRuleCBox.Text)); dlRuleCBox.Invoke(tasktoInvoke); return(getted); } else { return(Convert.ToString(dlRuleCBox.Text)); } return(""); break; case 2: if (TitlettBox.InvokeRequired) { string getted = ""; var tasktoInboke = new Action(() => getted = Convert.ToString(TitlettBox.Text)); TitlettBox.Invoke(tasktoInboke); return(getted); } else { return(Convert.ToString(TitlettBox)); } break; case 3: if (ModeCB.InvokeRequired) { string getted = ""; var tasktoInvoke = new Action(() => getted = Convert.ToString(ModeCB.Text)); dlRuleCBox.Invoke(tasktoInvoke); return(getted); } else { return(ModeCB.SelectedText); } break; default: return(""); break; } } else { return(""); } }
private void inteveneUIwithThread(string code) { //格式為Num/String //Num 指定要改部位 //string 用在內容物為布林時,當輸數字,大於0為真 //0=下載條件確認,1=開始下載按鈕,2=進度條,3=訊息欄,4=資料驗證CB,5=模式選擇CB,6=清空DlDataview,7=重設所選dl模式,8=系列名驗證CB if (!timetoClose) { string[] parsed = code.Split('/'); bool conver = false; switch (Convert.ToInt16(parsed[0])) { case 0: conver = Convert.ToInt16(parsed[1]) > 0 ? true : false; var checkDlPathCdtCB = new Action(() => DlPathCdtCB.Checked = conver); if (DlPathCdtCB.InvokeRequired) { DlPathCdtCB.Invoke(checkDlPathCdtCB); } else { DlPathCdtCB.Checked = true; } break; case 1: conver = Convert.ToInt16(parsed[1]) > 0 ? true : false; var setButton = new Action(() => initButton.Enabled = conver); if (initButton.InvokeRequired) { initButton.Invoke(setButton); } else { initButton.Enabled = conver; Console.Out.WriteLine(conver); } break; case 2: if (parsed[1].Equals("true") || parsed[1].Equals("false")) { conver = (parsed[1].Equals("true")) ? true : false; var setProbar1Visable = new Action(() => progressBar1.Visible = conver); if (progressBar1.InvokeRequired) { progressBar1.Invoke(setProbar1Visable); } else { progressBar1.Visible = conver; } } else { var setprogress = new Action(() => progressBar1.Value = Convert.ToInt16(parsed[1])); var updateprogrssbar = new Action(() => progressBar1.Update()); if (progressBar1.InvokeRequired) { progressBar1.Invoke(setprogress); progressBar1.Invoke(updateprogrssbar); } else { progressBar1.Value = Convert.ToInt16(parsed[1]); progressBar1.Update(); } } break; case 3: var writeLineTpTtbox = new Action(() => rTBox.Text += "\r\n"); var typeMessagesToTtbox = new Action(() => rTBox.Text += parsed[1]); if (rTBox.InvokeRequired) { rTBox.Invoke(writeLineTpTtbox); rTBox.Invoke(typeMessagesToTtbox); } else { typeMessageToTtBox(parsed[1]); } break; case 4: conver = Convert.ToInt16(parsed[1]) > 0 ? true : false; var checkListvcdtCB = new Action(() => ListvcdtCB.Checked = conver); if (ListvcdtCB.InvokeRequired) { ListvcdtCB.Invoke(checkListvcdtCB); } else { ListvcdtCB.Checked = conver; } break; case 5: var switchModeCB = new Action(() => ModeCB.SelectedIndex = Convert.ToInt16(parsed[1])); if (ModeCB.InvokeRequired) { ModeCB.Invoke(switchModeCB); } else { ModeCB.SelectedIndex = Convert.ToInt16(parsed[1]); } break; case 6: var clearDldataView = new Action(() => DldataView.Rows.Clear()); if (DldataView.InvokeRequired) { DldataView.Invoke(clearDldataView); } else { DldataView.Rows.Clear(); } break; case 7: var cleardlRuleCobBoxText = new Action(() => dlRuleCBox.SelectedText = ""); if (dlRuleCBox.InvokeRequired) { dlRuleCBox.Invoke(cleardlRuleCobBoxText); } else { dlRuleCBox.SelectedText = ""; } break; case 8: conver = Convert.ToInt16(parsed[1]) > 0 ? true : false; var setTitleVaildConditionCB = new Action(() => TitleCdtCB.Checked = conver); if (TitleCdtCB.InvokeRequired) { TitleCdtCB.Invoke(setTitleVaildConditionCB); } else { TitleCdtCB.Checked = conver; } break; case 9: var setTitleTTBoxToValue = new Action(() => TitlettBox.Text = parsed[1]); if (TitlettBox.InvokeRequired) { TitlettBox.Invoke(setTitleTTBoxToValue); } else { TitlettBox.Text = parsed[1]; } break; default: break; } } }