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

The Archive Base Latest Questions

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

I got a thread running every few seconds fetching some data from a db

  • 0

I got a thread running every few seconds fetching some data from a db
but this is based on the selection on a listbox and on a few checkboxes…
can I read the values of these controls without using the GUI thread?

The data is also read whenever one of the controls change, but the data might change in db
without warning…hence the thread running every few seconds.

I’m working with wpf C#

  • 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-15T21:55:10+00:00Added an answer on May 15, 2026 at 9:55 pm

    In short, no. Controls can only be accessed by the thread that created them.

    Prove it for yourself:

    <Window x:Class="ReadControlsBackground.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow"
            Height="350"
            Width="525">
        <StackPanel>
            <Button x:Name="Start"
                    Click="Button_Click"
                    Content="Start" />
            <ListBox x:Name="List">
                <ListBoxItem>One</ListBoxItem>
                <ListBoxItem>Two</ListBoxItem>
            </ListBox>
            <CheckBox x:Name="Check" />
        </StackPanel>
    </Window>
    
    
    
    using System;
    using System.Diagnostics;
    using System.Threading;
    using System.Windows;
    
    namespace ReadControlsBackground {
        /// <summary>
        ///   Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window {
            public MainWindow() {
                InitializeComponent();
            }
    
            private void Button_Click(object sender, RoutedEventArgs e) {
                Start.IsEnabled = false;
                var t = new Thread(Poll);
                t.Start();
            }
    
            private void Poll() {
                while (true) {
                    Debug.WriteLine(String.Format("List: {0}", List.SelectedValue));
                    Debug.WriteLine(String.Format("Check: {0}", Check.IsChecked));
                    Thread.Sleep(5000);
                }
            }
        }
    }
    

    Do something like this instead:

    private void Poll() {
        while (true) {
            var selected = (String) Dispatcher.Invoke((Func<String>) (() => (List.SelectedValue ?? "?").ToString()));
            var isChecked = (Boolean?) Dispatcher.Invoke((Func<Boolean?>) (() => Check.IsChecked));
            Debug.WriteLine(String.Format("List: {0}", selected));
            Debug.WriteLine(String.Format("Check: {0}", isChecked));
            Thread.Sleep(5000);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 505k
  • Answers 505k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you realize that filter conditions can be passed in… May 16, 2026 at 3:21 pm
  • Editorial Team
    Editorial Team added an answer It can be as simple as uploading a file like… May 16, 2026 at 3:21 pm
  • Editorial Team
    Editorial Team added an answer You need the put the characters you wish to split… May 16, 2026 at 3:21 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

A similar problem to mine is in this thread , but it doesn't use
I've got a thread (specifically an NSOperation) that runs to load some images for
I've got some threads doing heavy work while my main thread handles the UI
I've got a web application that's running really slowly and occasionally hanging. It's a
I'm developing a Cocoa app, and every so often when running my app in
At work we've got a very CPU-intensive Windows Forms application. It's running on a
I've got 64-bit Vista with ActiveState Perl v5.10.0 built for MSWin32-x64-multi-thread and I'm trying
I've got this code below, where I spawn several threads, normally about 7, and
Recently, I've been running some tests with C++ and VB.NET to compare execution speeds.
I have been given the task of re-writing some libraries written in C# so

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.