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 8876957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:20:45+00:00 2026-06-14T19:20:45+00:00

I am making an application using WPF and C#. What I’m trying to do

  • 0

I am making an application using WPF and C#. What I’m trying to do is to print a lots of shapes on a canvas with some time in between when I push a button. At the moment when I push the button, everything just pops up at once. I have tried to sleep the thread for some time between every “print” but that doesn’t help, it just take longer time before everything splash up at once. What I want to achive is that the shapes pop up one at a time with lets say 0.5 seconds in between. The code is the following:

   private void Create_Click(object sender, RoutedEventArgs e)
   {
        Random random = new Random();
        for (int i = 0; i < 50; i++)
        {
            Thread.Sleep(500);
            Path f = FlowerFactory.createFlower(FlowerBP, true);
            Canvas.SetLeft(f, random.Next(0, 1650));
            Canvas.SetTop(f, random.Next(0,1000));
            DrawBoard.Children.Add(f);
        }}
  • 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-14T19:20:47+00:00Added an answer on June 14, 2026 at 7:20 pm

    You need to, first, run the loop in a background thread so that it doesn’t block the UI from updating; and second, send the UI-rendering tasks back to the UI thread. For the first, you can use Task.Factory.StartNew, and for the second, use Dispatcher.Invoke:

    Random random = new Random();
    Task.Factory.StartNew(() =>
    {
        for (int i = 0; i < 50; i++)
        {
            Thread.Sleep(500);
            Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            {
                Path f = FlowerFactory.createFlower(FlowerBP, true);
                Canvas.SetLeft(f, random.Next(0, 1650));
                Canvas.SetTop(f, random.Next(0,1000));
                DrawBoard.Children.Add(f);
            }));
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a WPF application using MVVM pattern. I found sometimes Task is significantly
I'm working on a desktop project using WPF, framework 3.5. This application has lots
I am making a calculator using WPF Application in MS Visual Studio 2010. I
I'm trying to learn .NET and WPF, and I'm making a calculator type application
I am making an application using Silverlight. I must restict the access of some
I'm making a Wpf Application. My problem is that I'm using a DataGrid to
I'm trying to learn objective-c by making a GUI application using Xcode 3. I'm
I am making an application using LWUIT. There is a form There is a
I am making an application using two view controlers. When I am working on
I'm making an application using Quickly, and I want to add a Webkit widget

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.