473,789 Members | 2,957 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WPF: refresh a window during processing

In other languages I've worked with, there is a way to allow an app to go
idle just long enough for its windows to refresh. Can't find this in c#. I
did find some discussion of multithreading the app, but that seems like a
bunch of work to retrofit, given that I'd have to learn how to do it. Am I
missing something?

Jeremy

Jun 27 '08 #1
2 16715
Jeremy,

The best approach here is to use multithreading, as you have seen in
other threads. You will want to perform your work on another thread, and
then update the UI thread from the worker thread. Using something like
DoEvents (which is for windows forms, not for WPF, I am not sure if WPF has
an analogy) is just bad practice, and can introduce race conditions that are
unexpected if not accounted for.

In WPF, you would use the Dispatcher class to send notifications to the
UI thread.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Jeremy" <je***********@ ninprodata.comw rote in message
news:Od******** ******@TK2MSFTN GP02.phx.gbl...
In other languages I've worked with, there is a way to allow an app to go
idle just long enough for its windows to refresh. Can't find this in c#.
I did find some discussion of multithreading the app, but that seems like
a bunch of work to retrofit, given that I'd have to learn how to do it.
Am I missing something?

Jeremy
Jun 27 '08 #2
In other languages I've worked with, there is a way to allow an app to go
idle just long enough for its windows to refresh. Can't find this in c#.
I did find some discussion of multithreading the app, but that seems like
a bunch of work to retrofit, given that I'd have to learn how to do it.
Am I missing something?
Try this:

void DoEvents()
{
DispatcherFrame f = new DispatcherFrame ();
Dispatcher.Curr entDispatcher.B eginInvoke(Disp atcherPriority. Background,
(SendOrPostCall back)delegate(o bject arg)
{
DispatcherFrame fr = arg as DispatcherFrame ;
fr.Continue = false;
}, f);
Dispatcher.Push Frame(f);
}

But beware that this can give you problems with re-entrancy (just as VB6's
DoEvents could).

Chris Jobson
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3715
by: AJang | last post by:
My windows form "Form1" has one Button "button1" and one TextBox "textBox1". When I click button1, it do a job for each file in a directory. The job include some platform invoke call. Before processing a file, I set textBox1's Text property as filename of the file processed, and call this->refresh() to refresh the form. Every thing seems OK. But, if the process time for some file is a little long (say 10 seconds) and during processing...
2
7047
by: hufaunder | last post by:
I have to present inputs (textbox, combobox, etc) that are not known during design time. In the past this was pretty simple to do. You just add a new control to the Controls property of a form. How can I achieve the same thing with WPF? Thanks
0
1481
by: Yiyu | last post by:
Hi, I am a newbie here. Here what I want to do and I wonder if it's easy to be achieved using Windows Presentation Foundation: I am going to teach a college course and I want to do real time presentation on website, so if one of my students can't come to campus during class hours she can just log onto the course webpage and see / hear exactly what I am talking about. I want my course page to have following functions:
2
2900
by: Griff | last post by:
Hi I have a WPF application (VS 2008; .NET 3.5) which has several tab controls and listViews. When I start the application, it start in normal "window" mode. I can click between the Tabs and it's reasonably responsive. However, I've made the window resizeable.
0
1877
by: =?Utf-8?B?T2xhZg==?= | last post by:
Hi, I and my team are currently working on a project where we need to create an active document server that is hosting a WPF page. We are unsing VS 2008. We created the active document container as a MFC application that hosts the WPF page. Everything seems to work fine except the refresh of the WPF page. E.g. when the active document container is maximized and afterwards the size is restored sometimes the WPF page is nor drawn, just a...
23
4561
by: raylopez99 | last post by:
Here I am learning WinForms and two months into it I learn there's a WPF API that is coming out. Is this WPF out yet, and is it a threat to WinForms, in the sense that all the library routines I memorize and/ or familiarize myself in WinForms will disappear in WPF? I did note in one early version of C#, the non-generic "ArrayList" was replaced by the generic and template <based List, but that kind of change is not a big deal. If WPF...
2
3052
by: Dean Slindee | last post by:
Is there any control in WPF which can host a WPF window? If not now, are there any plans to improve WPF to implement window hosting. Related question: is it not possible to build a MDI application in WPF. If there is a WPF newsgroup, please direct me there. Thanks, Dean S
2
8923
by: Dean Slindee | last post by:
I am not looking for a "hybrid" WPF/WinForm or WinForm/WPF solution, but rather a pure WPF/WPFsolution. I want to host a WPF window inside another WPF window. I want to host a WPF window as a "control" inside another WPF window, much like a button is hosted inside a WPF window. This may not be possible today in WPF, but that is what I am trying to determine. Since WPF is a 1.0 product, perhaps the answer is: wait for a more complete...
0
1315
by: Andy | last post by:
Hi, I'm trying to understand why something does work. If you create a new WPF Applicatin project, WpfApplication6, and set the following: MainWindow.xaml: <Window x:Class="WpfApplication6.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:app="clr-namespace:WpfApplication6"
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10410
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5418
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.