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

  • SEARCH
  • Home
  • 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 8609903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:59:29+00:00 2026-06-12T03:59:29+00:00

so my problem is that when i set for my wpf application an endless

  • 0

so my problem is that when i set for my wpf application an endless thread the ui hangs but of course this is not what i expect from a multi-threaded application.

heres my code

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        System.Threading.Thread thread = new System.Threading.Thread(
            new System.Threading.ThreadStart(
                delegate
                {
                    Dispatcher.Invoke(DispatcherPriority.Normal,
                        new Action<Polyline>(ChangePoints), polyline);
                }));
        thread.Start();
    }

    private void ChangePoints(Polyline p)
    {
        while (true)
        {
            Random random = new Random();
            p.Points.Clear();
            for (int i = 0; i < 500; i += 10)
            {
                p.Points.Add(new Point(i, random.Next(1, 300)));
            }
        }
    }
}


<Window x:Class="ClientSide.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="300" Width="500">
    <Canvas x:Name="canvas" Background="#00FFFFFF">
        <Polyline x:Name="polyline" Stroke="DarkGreen" StrokeThickness="3" />
    </Canvas>
</Window>

can you guys tell me whats wrong in here?

  • 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-06-12T03:59:30+00:00Added an answer on June 12, 2026 at 3:59 am

    can you guys tell me whats wrong in here?

    You create a new thread, but then immediately use the Dispatcher to marshal the thread’s work onto the UI thread. This will cause it to run completely on the UI thread.

    Since you’re performing an infinite loop, this causes it to just lock up the UI thread indefinitely.

    To correct, you need to switch your logic around. Don’t marshal the call back onto the UI thread for the entire method, but instead build the points, and marshal only the call where you set p.Points within the loop. You may also need to create some form of delay in there, as it would be running as fast as possible (given the current code), which will likely make the UI unresponsive.

    Try something like the following:

    public MainWindow()
    {
        InitializeComponent();
        System.Threading.Thread thread = new System.Threading.Thread(
            new Action(() => ChangePoints(polyline)));
        thread.Start();
    }
    
    private void ChangePoints(Polyline p)
    {
        // Create once and reuse
        Random random = new Random();
    
        while (true)
        {
            PointCollection points = new PointCollection();
            for (int i = 0; i < 500; i += 10)
            {
                points.Add(new Point(i, random.Next(1, 300)));
            }
    
            // Now marshal back to the UI thread here...
            Dispatcher.Invoke(DispatcherPriority.Normal, 
                new Action( () => p.Points = points));
    
            // Optionally delay a bit here...
            Thread.Sleep(250);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I set up the basic Authentication/Authorization set up, but a problem now is that
I have a problem with a javascript set of functions that I made. This
I have just changed my WPF application from .Net3.5 to .Net4. Doing this caused
In a MVVM WPF application. How do you set a second windows parent from
I'm having a big problem when calling a web service from my WPF application.
I'm trying to bind to some XML data from my WPF application. I've set
Hi I am creating my first WPF application that uses Ribbons. The problem I
I have a WPF application that uses a custom window frame. My problem is
I'm trying to write a WPF application that will update a set of text
Im currently facing the problem that when i try to set focus on some

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.