How to force the UI to refresh immediately(WPF)
Question
Folks,
In my application, when the user hits "Submit" button, I have to make a Web service call asynchronously. Here is what I do.
1. Disable a bunch of controls, update some text:
this._btnSubmit.IsEnabled = false; ...
this._lblInfo.Text = "Connecting..."2. Use Dispatcher.BeginInvoke for the actual Web service call.
this.Dispatcher.BeginInvoke(DoTheStuff, DispatcherPriority.ContextIdle);
The idea is to that the UI will get updated before the actual asynchronous call to the Web service is made.
The problem is that the UI is not updating immediately. It takes a few seconds before the controls disable and the text appears.
What is it that I need to do to ensure that the UI gets updated?
I probably could spawn a background thread but that would be an overkill given that the Web service call is already asynchronous.
Thank you in advance for your help.
Regards,
PeterThursday, January 06, 2011 8:10 PMReply|Quote|
Answers
Hi Peter Taps,
Based on your description, I think you could try to below code snippet to achieve your goal(Force UI refresh).
private delegate void NoArgDelegate();
public static void Refresh(DependencyObject obj)
{
obj.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.ApplicationIdle,
(NoArgDelegate)delegate { });
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Refresh(testDtGrid);
}
Best regards,
Sheldon _Xiao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Marked as answer by Peter Taps Wednesday, January 12, 2011 7:27 PM
Monday, January 10, 2011 4:00 AMReply|Quote|
All replies
- I know this doesn't answer your question, but have you considered using a BusyIndicatorto disable interaction with the window, instead of manually enabling and disabling all the controls. Remember, this isn't WinForms. The Extended WPF Toolkit has a free one.Thursday, January 06, 2011 8:41 PMReply|Quote|
Hi Peter Taps,
Based on your description, I think you could try to below code snippet to achieve your goal(Force UI refresh).
private delegate void NoArgDelegate();
public static void Refresh(DependencyObject obj)
{
obj.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.ApplicationIdle,
(NoArgDelegate)delegate { });
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Refresh(testDtGrid);
}
Best regards,
Sheldon _Xiao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Marked as answer by Peter Taps Wednesday, January 12, 2011 7:27 PM
Monday, January 10, 2011 4:00 AM
_________________
for url: http://social.msdn.microsoft.com/Forums/vstudio/en-US/d651bd33-53fc-4218-9089-cd77d32f4fd8/how-to-force-the-ui-to-refresh-immediately?forum=wpf
How to force the UI to refresh immediately(WPF)的更多相关文章
- WPF如何实现一个漂亮的页签导航UI
最近看到一个比较漂亮的UI主界面,该UI是用左边的页签进行导航,比较有特色,就想着尝试用WPF来实现一下.经过一番尝试,基本上将UI设计图的效果用WPF程序进行了实现.下面介绍一下主要的思路: 1 U ...
- 利用HTML实现软件的UI
先看看下面的实例 这是应朋友之邀编写的查询职业技能鉴定考核的分数的软件.看过我之前的博文的,可知这是借用我之前的网页界面. 这个UI,如果用WinForm的控件来实现,难度很高. 于是另辟蹊径,用We ...
- 随心所欲导出你的 UI 界面到 PDF 文件
使用 C1PDF 控件可以导出文件到 PDF 文件,结合 .NET 平台特性你可以在任何客户端生成自定义报表.你可以打印任何 UI 界面,例如 DataGrid 导出到 PDF. 在本篇文章中我们将阐 ...
- Server-Side UI Automation Provider - WPF Sample
Server-Side UI Automation Provider - WPF Sample 2014-09-14 引用程序集 自动化对等类 WPF Sample 参考 引用程序集 返回 UIAut ...
- WPF案例 (六) 动态切换UI布局
原文:WPF案例 (六) 动态切换UI布局 这个Wpf示例对同一个界面支持以ListView或者CardView的布局方式呈现界面,使用控件ItemsControl绑定数据源,使用DataTempla ...
- (转)基于 WPF + Modern UI 的 公司OA小助手 开发总结
原文地址:http://www.cnblogs.com/rainlam163/p/3365181.html 前言: 距离上一篇博客,整整一个月的时间了.人不能懒下来,必须有个阶段性的总结,算是对我这个 ...
- 32.10 使用模板更改控件的UI
32.10 使用模板更改控件的UI 样式是改变WPF控件基本外形的非常好(且非常简单)的方式,它通过为窗口部件的特性设置建立一组默认的值,从而改变WPF控件的基本外形.但是,即使样式允许我们改变各种 ...
- 基于 WPF + Modern UI 的 公司OA小助手 开发总结
前言: 距离上一篇博客,整整一个月的时间了.人不能懒下来,必须有个阶段性的总结,算是对我这个阶段的一个反思.人只有在总结的过程中才会发现自己的不足. 公司每天都要在OA系统上上班点击签到,下班点击签退 ...
- WPF 支持的多线程 UI 并不是线程安全的
原文:WPF 支持的多线程 UI 并不是线程安全的 版权声明:本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可.欢迎转载.使用.重新发布,但务必保留文章署名吕毅(包含链 ...
随机推荐
- QT快速使用ntohs
QT快速使用ntohs,需要注意3点:1. ntohs只是转换相邻的2个字节2. 引入头文件#include <windows.h>3. 需要加上win32{LIBS+=-lws2_32} ...
- CSS动画 防止动画结束后,回归原位
animation-fill-mode防止动画结束后,回归原位 animation: arrowsfirst 1s; animation-timing-function: linear; animat ...
- 常用Maven插件介绍
我们都知道Maven本质上是一个插件框架,它的核心并不执行任何具体的构建任务,所有这些任务都交给插件来完成,例如编译源代码是由maven- compiler-plugin完成的.进一步说,每个任务对应 ...
- (BFS)poj1465-Multiple
题目地址 题意可理解为我们有一些给定的元素,要用它们组成数,如果一个长度(x)所有组成的数都不是给定的另一个数(n)的倍数,并且长度为x的数中有模n的不同于长度小于x的数模n的数,那么继续延长这个数的 ...
- 制造业如何基于BPM做供应链管理?
公司介绍深圳市吉祥腾达科技有限公司是中国网络产业的开航者,是中国无线网络领域的首批开拓者之一.历经10年的开拓创新,已经形成了拥有自主研发的全面产品线. 为了使公司物流.资金流和信息流实现优化整合,腾 ...
- mysql 中execute、executeQuery和executeUpdate之间的区别
在用纯JSP做一个页面报警功能的时候习惯性的用executeQuery来执行SQL语句,结果执行update时就遇到问题,语句能执行,但返回结果出现问题,另外还忽略了executeUpdate的返回值 ...
- 关于一些学习html和css的笔记
一.Html简介 全写: HyperText Mark-up Language 译名: 超文本标识语言 简释:一种为普通文件中某些字句加上标示的语言,其目的在于运用标签(tag)使文件 达到预期的 ...
- dij单源最短路纯模板
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> ...
- OD调试篇6--对一些真正的小程序进行一点点的修改
先打开这个程序看看,提醒你这是一个未注册版本的软件.会发现只能添加4个联系人,这显然是我不想看见的,于是我要对这个程序进行一些修改,嘿嘿... 通过OD载入这个程序 有一些(SEH)也就是异常,我们可 ...
- Asp.Net异步导入Excel
故事:用户在页面上传一个excel文件,程序把excel里的内容入库. 技术方案:保存文件在服务器,jquey Ajax 异步读取文件中的记录到数据库,在页面实时刷新导入情况 页面前端 <%@ ...
