Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 641195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:02:10+00:00 2026-05-13T21:02:10+00:00

There is the situation – i made some math modelling app on C#(WPF), showing

  • 0

There is the situation – i made some math modelling app on C#(WPF), showing it’s results in realtime vector graphics. Math is doing fine (iterative process, per frame drawing), but there is the problem – while i’m using additional thread to do calculations, to draw result is should use Dispatcher.BeginInvoke (each frame!) which is quite an expensive operation (profiling showed that it tooks almost 30% of time).
But if i try to do all in the UI thread, i would see only the last frame (as expected).

Calculations and showing the result is the only task of app, so i even don’t need GUI to response during the modelling – but i need to show results in realtime…

So i want to avoid BeginInvoke and at the same time to display results, and i don’t see a way. Any ideas how to arrange calculations in such way?
The graphics are displayed in DrawingVisual in some empty FrameworkElement.

Thx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:02:11+00:00Added an answer on May 13, 2026 at 9:02 pm

    Option 1: Rendering event

    Do your calculations on the separate thread, but queue changes to the UI and update them on the Rendering event. It would look like this:

    PresentationSource.FromVisual(window).CompositionTarget.Rendering += (obj, e) =>
    {
      foreach(var update in _queue)
        UpdateUI(update);
    }
    

    This code assumes _queue’s is a thread safe (synchronized) queue. You can create such a queue class or download one. Alternatively you can surround the “foreach” with a “lock(_queue)”.

    The reasons this is better than Dispatcher.BeginInvoke() are: 1. It is called just before each frame so if the frame rate goes down it is called less frequently, and 2. It processes the changes in batches.

    Option 2: Multiple UI threads

    You can run a portion of your UI on a separate thread by using a separate hWnd. You can use WindowsFormsIntegration for this or use some Win32 magic. Here is one way to do it:

    1. In the new thread, construct the Window and show it (don’t forget to Appliation.Run())
    2. Once the new window is shown, get the hWnd using ((HwndSource)PresentationSource.FromVisual(window)).Handle
    3. Pass the hWnd back to the main UI thread using a Monitor or ManualResetEvent
    4. Use WindowsFormsHost to construct a container for the hWnd and add it to your UI
    5. Handle resize events in the main UI, passing them down to the contained window

    Option 3: Animations

    You can create your own custom Animation-derived classes to animate your UI items. These can use data precaculated from the model. The advantage of doing this is precise time synchronization: Every time your code is called it knows exactly “when” (in animation time) it is calculating the position for. So if some other program hogs the CPU or GPU for a second and slows down and the frame rate, the animation still proceeds smoothly at the lower frame rate.

    To do this, subclass DoubleAnimationBase and override GetCurrentValueCore() to do your custom calculation, combined with the required Clone() and CreateInstanceCore() overrides. Then use this to animate your properties.

    If simply animating Double properties of existing objects is not enough, it is possible to create an animation that produces entire objects such as Geometry, Geometry3D, Drawing, Drawing3D or even UIElement. To do this, subclass AnimationTimeline and override GetCurrentValue() along with the others.

    The advantage of using animations is the same as with the rendering event, except you can let WPF handle all the clock synchronization and replay speed issues for you instead of doing it yourself. It may also result in less code if you can animate only the properties that are changing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following situation: There is a tool that gets an XSLT from
Is there anything better than a Trie for this situation? Storing a list of
Is there a PostgreSQL HA solution that can handle a splitbrain situation gracefully. To
In this particular situation, there are 9 automated steps in a process that take
Are there techniques for comparing the same data stored in different schemas? The situation
Here is the situation: User looks something up. Alert sound is played because there
Is there any situation in which notify() can cause deadlock, but notifyAll() - never?
Are there any situations when you would use assertion instead of exceptions-handling inside domain
In my project there are situations where we have to send xml messages (as
Using ASP.NET MVC there are situations (such as form submission) that may require a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.