471,326 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,326 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 16110
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by hufaunder | last post: by
2 posts views Thread by Griff | last post: by
reply views Thread by =?Utf-8?B?T2xhZg==?= | last post: by
23 posts views Thread by raylopez99 | last post: by
2 posts views Thread by Dean Slindee | last post: by
2 posts views Thread by Dean Slindee | last post: by
reply views Thread by Andy | last post: by
reply views Thread by rosydwin | last post: by

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.