• c# 线程 WPF 进度百分比(菜鸟)


            #region 线程执行
            /// <summary>
            /// 线程运行,将改变的textblock值实时显示在前台
            /// </summary>
            /// <param name="tb"></param>
            private void Computer(TextBlock tb)
            {
                for (int i = 1; i <= 100; i++)
                {
                    Random rd = new Random();
                    var num = i;
                    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate () { tb.Text = num + "%"; if (tb.Text == "100%") { tb.Text = "完成"; } });
                    Thread.Sleep(rd.Next(1, 101));
                }
            }
            #endregion 线程执行_end
            /// <summary>
            /// 点击开始
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
            {
                //将选中的行数据,进度从“0%”--“100%”,然后状态变为完成
                //以上Id开始执行
                DataGridTemplateColumn column = this.datagrid1.Columns[7] as DataGridTemplateColumn;
                foreach (var item in this.datagrid1.Items)
                {
                    var element = column.GetCellContent(item);
                    if (element != null)
                    {
                        TextBlock tb = column.CellTemplate.FindName("Plan", element) as TextBlock;
                        if (bcidL.Where(x => x.Id == Convert.ToInt32(tb.Tag)).Count() > 0)
                        {
                            #region 线程
                            Thread t = new Thread(() => { Computer(tb); });
                            t.Start();
                            #endregion
                        }
                    }
                }
            }
  • 相关阅读:
    java.lang.NoClassDefFoundError: org.junit.runner.Runner
    SpringMVC 八大注解
    spring @autowired使用总结
    Git使用入门
    N21_栈的压入弹出序列。
    N20_包含min函数的栈
    N19_顺时针打印指针
    N17_判断树B是不是树A的子结构
    N16_合并两个排序链表
    N15_反转链表后,输出新链表的表头。
  • 原文地址:https://www.cnblogs.com/SeNaiTes/p/9443957.html
Copyright © 2020-2023  润新知