472,951 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,951 software developers and data experts.

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 16534
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.