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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:40:24+00:00 2026-05-26T21:40:24+00:00

I have been working with WPF and threading. I would like to pause the

  • 0

I have been working with WPF and threading.

I would like to pause the whole screen (the application only) during a for loop.

E.g.

foreach (classA a in classesA)
{
....
....
Thread.sleep(100);

}

However, I found that it will sleep for long and then execute all the statement in a time.
It is not what I want. I want to sleep within the execution of the for loop. That is to sleep 100ms after 1st loop, then sleep again after the 2nd loop…..

I found that some article mentioned DoEvents(), but I am not quite familiar with it and WPF seem don’t have this kind of thing.

Some other articles mentioned DispatcherTimer. Still, it will not lock the screen.
I would like to lock the whole screen (the application only) to prevent from clicking any button during the execution of the for loop.

How could I do so?

Thank you so much!

  • 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-26T21:40:24+00:00Added an answer on May 26, 2026 at 9:40 pm

    If you are willing to experiment to with the proposed async and await keywords you could achieve the sleep behavior with synchronous semantics like this. You would need to install the Async CTP to do it though.1

    public aysnc void YourButton_Click(object sender, EventArgs args)
    {
      foreach (classA a in classes)
      {
        await Task.Delay(100);
      }
    }
    

    1The Async CTP uses TaskEx instead of Task.

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

Sidebar

Related Questions

I have been working on a WPF Application that is essentially a WYSIWYG editor,
I've only been working with WPF for a few months, but I have an
I have been working on a C# 4.0 WPF project and need to figure
I have been working with relational databases for sometime, but it only recently occurred
I've been working on a commandline application, and have recently decided to add a
I have been working in WPF web browsers lately but I can't seem to
I have been working with WPF all of 2 days, coming from ASP.NET so
I've been working on a WPF application and need to be able to show
I am currently working on the WPF project which involves creating a touch-screen application
I have been working through some of the examples of MVVM & WPF and

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.