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,
      Peter

      Thursday, January 06, 2011 8:10 PM
      Reply
      |
      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 AM
      Reply
      |
      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 PM
      Reply
      |
      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)的更多相关文章

  1. WPF如何实现一个漂亮的页签导航UI

    最近看到一个比较漂亮的UI主界面,该UI是用左边的页签进行导航,比较有特色,就想着尝试用WPF来实现一下.经过一番尝试,基本上将UI设计图的效果用WPF程序进行了实现.下面介绍一下主要的思路: 1 U ...

  2. 利用HTML实现软件的UI

    先看看下面的实例 这是应朋友之邀编写的查询职业技能鉴定考核的分数的软件.看过我之前的博文的,可知这是借用我之前的网页界面. 这个UI,如果用WinForm的控件来实现,难度很高. 于是另辟蹊径,用We ...

  3. 随心所欲导出你的 UI 界面到 PDF 文件

    使用 C1PDF 控件可以导出文件到 PDF 文件,结合 .NET 平台特性你可以在任何客户端生成自定义报表.你可以打印任何 UI 界面,例如 DataGrid 导出到 PDF. 在本篇文章中我们将阐 ...

  4. Server-Side UI Automation Provider - WPF Sample

    Server-Side UI Automation Provider - WPF Sample 2014-09-14 引用程序集 自动化对等类 WPF Sample 参考 引用程序集 返回 UIAut ...

  5. WPF案例 (六) 动态切换UI布局

    原文:WPF案例 (六) 动态切换UI布局 这个Wpf示例对同一个界面支持以ListView或者CardView的布局方式呈现界面,使用控件ItemsControl绑定数据源,使用DataTempla ...

  6. (转)基于 WPF + Modern UI 的 公司OA小助手 开发总结

    原文地址:http://www.cnblogs.com/rainlam163/p/3365181.html 前言: 距离上一篇博客,整整一个月的时间了.人不能懒下来,必须有个阶段性的总结,算是对我这个 ...

  7. 32.10 使用模板更改控件的UI

    32.10  使用模板更改控件的UI 样式是改变WPF控件基本外形的非常好(且非常简单)的方式,它通过为窗口部件的特性设置建立一组默认的值,从而改变WPF控件的基本外形.但是,即使样式允许我们改变各种 ...

  8. 基于 WPF + Modern UI 的 公司OA小助手 开发总结

    前言: 距离上一篇博客,整整一个月的时间了.人不能懒下来,必须有个阶段性的总结,算是对我这个阶段的一个反思.人只有在总结的过程中才会发现自己的不足. 公司每天都要在OA系统上上班点击签到,下班点击签退 ...

  9. WPF 支持的多线程 UI 并不是线程安全的

    原文:WPF 支持的多线程 UI 并不是线程安全的 版权声明:本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可.欢迎转载.使用.重新发布,但务必保留文章署名吕毅(包含链 ...

随机推荐

  1. C# 反射/映射学习

    反射其实就是为了能够在程序运行期间动态的加载一个外部的DLL集合,然后通过某种办法找到这个DLL集合中的某个空间下的某个类的某个成员(通过反射可以访问该类所包含的所有成员,不论成员是公有还是私有) 1 ...

  2. c# 配置文件之configSections配置(二)

    在很多时候我们需要自定义我们自己的自定义App.config 文件,而微软为我们提供了默认的 System.Configuration.DictionarySectionHandler System. ...

  3. C++ STL算法系列2---find ,find_first_of , find_if , adjacent_find的使用

    一.find运算 假设有一个int型的vector对象,名为vec,我们想知道其中是否包含某个特定值. 解决这个问题最简单的方法时使用标准库提供的find运算: 1 // value we'll lo ...

  4. Java中文档制作与继承

    1:如何制作帮助文档(了解) (1)写一个类 (2)加入文档注释 (3)通过javadoc工具生成即可 javadoc -d 目录 -author -version ArrayTool.java 2: ...

  5. 2014年4月底至5月初51Aspx源码发布详情

    精灵豆会员管理系统源码  2014-4-21 [VS2010]功能介绍:精灵豆会员管理系统业务管理平台采用微软选进的C#语言开发,采用大型数据库,具有比较高的执行效率和高安全性.系统分为消费管理,会员 ...

  6. 快速排序C++

    /* * quick_sort.cpp * * Created on: 2016-3-21 * Author: Lv_Lang */ //快速排序 #include <iostream> ...

  7. 团队开发——冲刺1.d

    冲刺阶段一(第四天) 1.昨天做了什么? 完成部分界面设置,补充三层难度界面.游戏结束界面. 2.今天准备做什么? 优化界面细节.查看C#资料,再解决自己电脑的问题. 3.遇到什么困难? 已经固定好的 ...

  8. C#常用操作类库三(XML操作类)

    /// <summary> /// XmlHelper 的摘要说明. /// xml操作类 /// </summary> public class XmlHelper { pr ...

  9. 黑马程序员:Java编程_集合

    =========== ASP.Net+Android+IOS开发..Net培训.期待与您交流!=========== 面向对象语言对事物的体现都是以对象的形式,所以为了方便对多个对象的操作,就对对象 ...

  10. 2015GitWebRTC编译实录17-audio_processing_neon编译问题解决

    编译audio_processing_neon lib时,发现只要涉及到WEBRTC_ARCH_ARM64就会出现问题,仔细回想了下,年初编译旧版本解决arm64支持问题时,好像也是要把这个注掉,但是 ...