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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:35:09+00:00 2026-05-23T20:35:09+00:00

before posting the question i did my research for 10 days so really hope

  • 0

before posting the question i did my research for 10 days so really hope someone can shed some light into solving this issue.

The issue is that any bindable control, does not update once the binding list from singleton class is changed. This is a common issue on multi-threaded apps. Most if not all solutions offer suggestions where the bindlinglist or collection is initialized from parent thread, and then some invocation to be made. Not what i’m looking for. The same issue persist if static class is used instead of singleton.

Basically, the application triggers some Tasks, which in turn create object(s) on different business classes. These objects post messages into the bindinglist, which should update the UI listbox, but does not. And yes, the message object is in the list, and binding after the TASK finished works (items displayed). Locking/unlocking object(s) access is also not an issue.

Appreciate any suggestions/solutions

A trimmed down version of business objects:

namespace MyNameSpace
{
    public class Message
    {
        private string messageSummary;
        public Message() { }
        public string MessageSummary
        {
            set { messageSummary = value; }
            get { return messageSummary; }
        }
    }
}

A trimmed down version of another class doing some ops:

namespace MyNameSpace
{
    public class WorkDoingClass
    {
        public WorkDoingClass() { }
        public void DoSomeWork()
        {
            //some routines
            Message messageObj = new Message();
            messageObj.MessageSummary = "DoSOmrWork Finished";
        }

        public void DoSomeOtherWork()
        {
            //some routines
            Message messageObj = new Message();
            messageObj.MessageSummary = "DoSomeOtherWork Finished";
            AllMessages.Instance.AllMessagesBindingList.Add(messageObj);
        }
    }
}

Singleton:

namespace MyNameSpace
{
    public sealed class AllMessages
    {
        private static readonly AllMessages _instance = new AllMessages();
        private BindingList<Message> _allMessagesBL;

        public WorkDoingClass() { _allMessagesBL = new BindingList<Message>(); }

        public static AllMessages Instance
        {
            get { return _instance; }
        }

        public BindingList<Message> AllMessagesBindingList
        {
            get { return _allMessagesBL};
        }
    }
}

This is also a trimmed down version from where calls start:

namespace MyNameSpace
{
    public partial class Form1 : Form
    {
        private Task _TaskSqlData;
        private CancellationTokenSource cTokenSourceSql;

        public Form1()
        {
            InitializeComponent();
            listBox1.DataSource = AllMessages.Instance.AllMessagesBindingList;
            listBox1.DisplayMember = "MessageSummary";
        }

    private void button1_Click(object sender, EventArgs e)
    {
            cTokenSourceSql = new CancellationTokenSource();
            var tokenSqlData = cTokenSourceSql.Token;
            if (this._TaskSqlData != null)
            {
                if (this._TaskSqlData.Status == TaskStatus.Running)
                    this.cTokenSourceSql.Cancel();
                this._TaskSqlData.Dispose();
                this._TaskSqlData = null;
            }
            _TaskSqlData = Task.Factory.StartNew(()
                            => StartDoingWork(this, tokenSqlData, null), tokenSqlData);
    }

    public void StartDoingWork(object sender, CancellationToken ct, EventArgs e)
    {
            if (ct.IsCancellationRequested)
                ct.ThrowIfCancellationRequested();
            WorkDoingClass work = new WorkDoingClass();
            work.DoSomeOtherWork();
    }
  • 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-23T20:35:10+00:00Added an answer on May 23, 2026 at 8:35 pm

    Your problem is that the thread(the main UI thread) making the listbox is different from the thread(the worker thread) modifying the collection.

    Try the following code. It could solve your issue. I use SynchronizationContext to synchronize the two threads, which serves as the same function with Control.Invoke().

    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            private Task _TaskSqlData;
            private CancellationTokenSource cTokenSourceSql;
            WorkDoingClass _work;
    
            public Form1()
            {
                InitializeComponent();
                listBox1.DataSource = AllMessages.Instance.AllMessagesBindingList;
                listBox1.DisplayMember = "MessageSummary";
                _work = new WorkDoingClass(SynchronizationContext.Current);
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                cTokenSourceSql = new CancellationTokenSource();
                var tokenSqlData = cTokenSourceSql.Token;
                if (this._TaskSqlData != null)
                {
                    if (this._TaskSqlData.Status == TaskStatus.Running)
                        this.cTokenSourceSql.Cancel();
                    this._TaskSqlData.Dispose();
                    this._TaskSqlData = null;
                }
                _TaskSqlData = Task.Factory.StartNew(()
                                => StartDoingWork(this, tokenSqlData, null), tokenSqlData);
            }
    
            public void StartDoingWork(object sender, CancellationToken ct, EventArgs e)
            {
                if (ct.IsCancellationRequested)
                    ct.ThrowIfCancellationRequested();
    
                _work.DoSomeOtherWork();
            }
        }
    
        public class Message
        {
            private string messageSummary;
            public Message() { }
            public string MessageSummary
            {
                set { messageSummary = value; }
                get { return messageSummary; }
            }
        }
    
        public class WorkDoingClass
        {
            private SynchronizationContext _syncContext;
    
            public WorkDoingClass() { }
    
            public WorkDoingClass(SynchronizationContext _syncContext)
            {
                // TODO: Complete member initialization
                this._syncContext = _syncContext;
            }
            public void DoSomeWork()
            {
                //some routines
                Message messageObj = new Message();
                messageObj.MessageSummary = "DoSOmrWork Finished";
            }
    
            public void DoSomeOtherWork()
            {
                _syncContext.Send(DoWork, null);
            }
    
            private static void DoWork(object arg)
            {
                //some routines
                Message messageObj = new Message();
                messageObj.MessageSummary = "DoSomeOtherWork Finished";
                AllMessages.Instance.AllMessagesBindingList.Add(messageObj);
            }
        }
    
        public sealed class AllMessages
        {
            private static readonly AllMessages _instance = new AllMessages();
            private BindingList<Message> _allMessagesBL;
    
            public AllMessages() { _allMessagesBL = new BindingList<Message>(); }
    
            public static AllMessages Instance
            {
                get { return _instance; }
            }
    
            public BindingList<Message> AllMessagesBindingList
            {
                get { return _allMessagesBL; }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I hope I've got everything listed up nicely before posting this question because
I did scour the net and stackoverflow before posting this question, so forgive me
I did check those posts about Infinite gallery before posting this question but it
I did search before posting this question and didn't find anything directly related, so
NOTE : Right before posting this question it occurred to me there's a better
Tried posting this before but it did not go through (i think) so if
I read through several questions similar to this one before posting, but did not
Before posting my question, I would like to tell you that I have no
Before posting my question to the ActiveState forum, I'd like to try luck here
I have seen the following links before posting this question http://www.devx.com/wireless/Article/40792/1954 Saving Android Activity

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.