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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:58:17+00:00 2026-06-13T01:58:17+00:00

I need to constantly poll a data store for possible updates. I am achieving

  • 0

I need to constantly poll a data store for possible updates. I am achieving this using the following code. This is a windows forms application by the way.

var uiContext = TaskScheduler.FromCurrentSynchronizationContext();

var updateTask = Task.Factory.StartNew(() =>
{
    while (true)
    {
        Thread.Sleep(5000);

        Task.Factory.StartNew(() =>
        {
            someData = dataStore.GetData();
        }).ContinueWith(t =>
        {
            someGrid.DataSource = someData;
        }, uiContext);
    }
});

someData is a private class field and someGrid is a datagrid control.

This seems to work perfectly, but I was wondering if there is a better way of achieving it. Also, should my outer Task be LongRunning?

EDIT:

Ok, at the suggestion of Jon and Henk, I am using a Timer instead:

uiContext = TaskScheduler.FromCurrentSynchronizationContext();

updateTimer = new System.Timers.Timer(5000);
updateTimer.Elapsed += updateTimer_Elapsed;
updateTimer.Enabled = true;

The elapsed event:

void updateTimer_Elapsed(object sender, ElapsedEventArgs e)
{
    someData = dataStore.GetData();

    Task.Factory.StartNew(() =>
    {
        someGrid.DataSource = someData;
    }, uiContext);
}
  • 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-13T01:58:18+00:00Added an answer on June 13, 2026 at 1:58 am

    Instead of Sleep()ing in a PoolThread you could/should use a Timer.
    For WinForms you can simply use the Widows.Forms.Timer.

    If you do want to do it this way then Yes, use the Longrunning option. But it is still wasting a Thread.

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

Sidebar

Related Questions

I need to constantly monitor a Twitter stream using Heroku. Basically what I want
I have some 150+ PNG in my application that I need to constantly read.
I have a program which executes constantly and I need to save data every
I need to constantly merge (upsert/delete) data from an ODBC data source to a
I am programming a Java app in which i need to constantly check that
I need a very simple jQuery to constantly scroll a list of text items
I need about 1,000 words to be able to be accessed constantly by my
so i have a list where i need to add new values constantly but
I've switched from using constants for Strings to using enums. Many times I need
I'm in dilema whether to use windows service for my application or not, below

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.