如何处理长期运行和QUOT;螺纹"在WPF?螺纹、如何处理、QUOT、WPF

2023-09-03 01:15:53 作者:星辰落了

晚上好!

目前我正在开发一个WPF客户端一些休息服务。与其余的服务的各项通讯是没有问题的,并在一个额外的装配完成(各项通讯接口)。

currently i'm developing a wpf-client for some rest-service. the communcation with the rest-service is no problem and is done in an extra assembly (communcation-interface).

基本上是: 我有一个莫名其妙的搜索 - 按钮,它执行的方法。这种方法与服务进行通信,并更新了一些文本框和一个进度条(给用户一些图形信息,我们还有多远?)。 unfortunaly服务器,它承载的服务是有点跛,造成了一些严重的响应时间(约4秒)。这一点,另一方面,使我的WPF应用程序等,从而结束了在:去黑,titeling没有响应......

basically: i have a somehow "search"-button which executes a method. this method communicates with the service, updates some textboxes and a progress-bar (to give the user some graphic info, how far we are ...). unfortunaly the server, which hosts the service is a bit lame, causing some severe response-time (about 4 secs). this, on the other hand, causes my wpf-application to wait, which ends up in: going black, and titeling "not responding" ...

我已经试图把这种执行在另一个线程,但...这是合乎逻辑的,我不会得到任何访问我的WPF窗口的控制......

i've already tried to put this execution in another thread, but ... it's logical that i won't get any access to the controls of my wpf-window ...

ATM我真的很无奈...谁能给我一些HANDELING例程或解决方案?

atm i'm really helpless ... can anyone give me some handeling-routine or a solution?

推荐答案

此影片演示了如何创建使用WPF和 Dispatcher.BeginInvoke 方法异步进度条。这是一个不错的温和简介基本跨线程问题在WPF一个简单的解决方案。

This video shows how to create an asynchronous progress bar using WPF and the Dispatcher.BeginInvoke method. It's a nice gentle introduction to a simple solution for basic cross threading issues in WPF.