473,473 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Create 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 16675
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.com

"Jeremy" <je***********@ninprodata.comwrote in message
news:Od**************@TK2MSFTNGP02.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.CurrentDispatcher.BeginInvoke(Dispatche rPriority.Background,
(SendOrPostCallback)delegate(object arg)
{
DispatcherFrame fr = arg as DispatcherFrame;
fr.Continue = false;
}, f);
Dispatcher.PushFrame(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
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...
2
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...
0
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...
2
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...
0
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...
23
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...
2
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...
2
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...
0
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...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.