public partial class frmSSQ : Form { public frmSSQ() { InitializeComponent();
this.btnStart.Enabled = true; this.btnStop.Enabled = false; } #region Data ///
<summary> /// 红球集合 其实可以写入配置文件 /// </summary> private string[] RedNums = { "01",
"02","03","04","05","06","07","08","09","10", "11","12","13","14","15","16","17"
,"18","19","20", "21","22","23","24","25","26","27","28","29","30", "31","32",
"33" }; /// <summary> /// 蓝球集合 /// </summary> private string[] BlueNums = { "01"
,"02","03","04","05","06","07","08","09","10", "11","12","13","14","15","16" };
private bool IsGoOn = true; private List<Task> taskList = new List<Task>(); #
endregion #region UI /// <summary> /// 点击开始: /// </summary> /// <param
name="sender"></param> /// <param name="e"></param> private void btnStart_Click(
object sender, EventArgs e) { try { #region 初始化动作 this.btnStart.Text = "运行ing";
this.btnStart.Enabled = false; this.IsGoOn = true; this.taskList = new List<Task
>(); this.lblBlue.Text = "00"; this.lblRed1.Text = "00"; this.lblRed2.Text =
"00"; this.lblRed3.Text = "00"; this.lblRed4.Text = "00"; this.lblRed5.Text =
"00"; this.lblRed6.Text = "00"; #endregion Thread.Sleep(1000); foreach (var
controlin this.gboSSQ.Controls) { if (control is Label) { Label label = (Label)
control; if (label.Name.Contains("Blue")) { taskList.Add(Task.Run(() => { try {
while (IsGoOn) { //1 获取随机数 int index = new RandomHelper().GetRandomNumberDelay(0
, 16); string sNumber = this.BlueNums[index]; //2 更新界面 //this.lblBlue.Text =
sNumber; //子线程不能操作控件,委托给主线程操作 //this.Invoke this.Invoke(new Action(() => { label
.Text = sNumber; })); //3 循环 } } catch (Exception ex) { Console.WriteLine(ex.
Message); } })); } else if (label.Name.Contains("Red")) { taskList.Add(Task.Run(
() => { try { while (IsGoOn) { int index = new RandomHelper().
GetRandomNumberDelay(0, 33); string sNumber = this.RedNums[index]; //可能重复 得去重
//1 过河的卒子 一次性拿6个,一次更新,但是界面更新有规律 //2 再来个数组标记一下,有点笨拙;其实界面不就有吗? //3 80奋斗
数据分隔,安全高效,但是有规律 //检测下是否重复, 直接比对界面 //获取随机 比对界面 更新 lock (SSQ_Lock) { List<string>
usedNumberList= this.GetUsedRedNumbers(); if (!usedNumberList.Contains(sNumber))
{ this.Invoke(new Action(() => { //Thread.Sleep(10); label.Text = sNumber; }));
//实际上是同步的 } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } })); }
} } Task.Factory.ContinueWhenAll(this.taskList.ToArray(), tArray => { this.
ShowResult(); this.Invoke(new Action(() => { this.btnStart.Enabled = true; this.
btnStop.Enabled = false; })); }); Task.Delay(10 * 1000).ContinueWith(t => { this
.Invoke(new Action(() => { this.btnStop.Enabled = true; })); }); } catch (
Exception ex) { Console.WriteLine("双色球启动出现异常:{0}", ex.Message); } } private
static readonly object SSQ_Lock = new object(); private List<string>
GetUsedRedNumbers() { List<string> usedNumberList = new List<string>(); foreach
(var controler in this.gboSSQ.Controls) { if (controler is Label) { if (((Label)
controler).Name.Contains("Red")) { usedNumberList.Add(((Label)controler).Text);
} } } return usedNumberList; } /// <summary> /// 点击结束 /// </summary> /// <param
name="sender"></param> /// <param name="e"></param> private void btnStop_Click(
object sender, EventArgs e) { this.IsGoOn = false; } /// <summary> /// 弹框提示数据
/// </summary> private void ShowResult() { MessageBox.Show(string.Format(
"本期双色球结果为:{0} {1} {2} {3} {4} {5} 蓝球{6}" , this.lblRed1.Text , this.lblRed2.Text
, this.lblRed3.Text , this.lblRed4.Text , this.lblRed5.Text , this.lblRed6.Text
, this.lblBlue.Text)); } #endregion #region PrivateMethod #endregion }

技术
©2019-2020 Toolsou All rights reserved,
份额已超宁德时代!LG化学确认将分拆电池业务部门Qt学习7——模态和非模态对话框数字滚动抽奖小程序vue 监听 Treeselect 选择项的改变 dedecms网站被黑 劫持到其他网站如何解决内存溢出和内存泄漏的区别、产生原因以及解决方案SQL Server 数据库词汇表1190 反转每对括号间的子串 leetcode蝗灾虫群上亿只很少发生碰撞 蝗虫要成自动驾驶功臣最优化方法总结:公式解、数值优化、求解思想