小编Des*_*tor的帖子

调用UI-Element时线程运行缓慢

我正在编写一个基准测试工具,它从一个线程中的本地服务器读取一堆变量.

            int countReads = 1000;

            Int64 count = 0;

            for (int i = 0; i < countReads; i++)
            {
                Thread.CurrentThread.Priority = ThreadPriority.Highest;
                DateTime start = DateTime.Now;

                session.Read(null, 0, TimestampsToReturn.Neither, idCollection, out ReadResults, out diagnosticInfos);

                DateTime stop = DateTime.Now;
                Thread.CurrentThread.Priority = ThreadPriority.Normal;

                TimeSpan delay = (stop - start);

                double s = delay.TotalMilliseconds;
                count += (Int64)s;

                Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
                {
                    progressBar1.Value = i;
                }));
            }

            double avg = (double)count / countReads;

            Dispatcher.Invoke(DispatcherPriority.Input, new Action(() =>
            {
                listBox1.Items.Add(avg);
            }));
Run Code Online (Sandbox Code Playgroud)

我正在计算进行读取和获得平均时间跨度所花费的时间跨度.

            DateTime start …
Run Code Online (Sandbox Code Playgroud)

c# wpf user-interface multithreading dispatcher

3
推荐指数
1
解决办法
5099
查看次数

标签 统计

c# ×1

dispatcher ×1

multithreading ×1

user-interface ×1

wpf ×1