线程开始滞后UI WPF [英] Thread Starts lags UI WPF

查看:120
本文介绍了线程开始滞后UI WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,我一直挣扎着这一段时间,我一直无法找到一个解决方案。 我发展,你在一切工作快得要命超市看到那些收银员应用程序之一。收银员知道程序那么好,他们只需要输入以光的速度,使用户界面必须是令人难以置信的反应。

Well, I've been struggling with this for a while and I've been unable to find a solution. I' developing one of those cashier apps you see in the supermarket where everything works fast as hell. The cashiers know the program so good they just type at the speed of light so the UI must be incredible responsive.

不管怎样,正如我在WPF已经只有codeD我使用它,如果有人说的WinForms更快我一定会了解它。 这是我的code,这是非常简单,我测试的性能

Anyway, as I've only coded in WPF I'm using it, if someone says WinForms is faster I'll surely learn it. This is my code, it's very simple as I'm testing performance

    public partial class MainWindow : Window
{
    Thread t;
    public MainWindow()
    {
        InitializeComponent();


    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {

        t = new Thread(HandleThread);
        t.Start();


    }


    private void HandleThread()
    {
        Thread.Sleep(3000);
    }

}

每当点击我打算连接到服务器,在新线程一个新的线程启动按钮。 我的问题是该方法button_Click是很慢的。这需要大约1秒钟,返回使按键看起来像它卡住,应用程序看起来呆滞。我trye​​d主题,BackgroundWorker的,改变了框架4.0和tryed任务。 NOTHING。无论我做什么,开始了某种backgound工作方法需要永远。

Whenever the button is clicked a new thread is launched as I plan on connecting to a server in the new thread. My problem is the method button_Click is VERY SLOW. It takes about 1 second to return so the button looks like it's stuck and the application look sluggish. I've tryed Thread, BackgroundWorker, changed the framework to 4.0 and tryed Tasks. NOTHING. Whatever I do to start some kind of backgound work the method takes forever.

我需要检查一个远程服务器上的用户名和密码,我该怎么完成它不伤害用户界面?

I need to check the username and password on a remote server, how can I accomplish it without hurting the UI?

推荐答案

您应该关闭的IntelliTrace(的 操作方法 )。

You should turn off the IntelliTrace (How-To).

  1. 在工具菜单上,单击选项。
  2. 在选项对话框,展开的IntelliTrace节点,然后单击常规。
  3. 清除启用的IntelliTrace复选框。
  4. 点击确定。

这篇关于线程开始滞后UI WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆