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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:31:46+00:00 2026-06-06T01:31:46+00:00

Goal: Once i click on the start button on my user interface, i currently

  • 0

Goal:

Once i click on the start button on my user interface, i currently fire two background workers.

BGWorker 1 is responsible for invoking the .dll method to crawl a website
BGWorker 2 is responsible for updating the DataGridView using the Datasource = source setter

Issues:

My dll receives as argument, the reference to the Data Source that will be populated while the .dll is running. So Basically, the .dll is going to add a object in the data source once in a while, until it finishes running.

The BGWorker 2 does this :

while (1 == 1) // Runs until is it manually disposed
{
    CoursesGrid.BeginInvoke // inline method 
    (
        (Action) delegate 
        {
            if (_coursesSource.Count > 0) // if source is not empty,Binds.
            {
                try
                { 
                    CoursesGrid.DataSource = _coursesSource;
                    CoursesGrid.EndEdit();
                }
                catch (Exception ex)
                {
                    Logs.LogWriter.LogError(ex);
                }                   
            }
            else
            {
                // Signals User To keep Waiting
            }
        }
     );
Thread.Sleep(4000);

Behavior flow:

  • Dll is Invoked
  • Method Parses a element and adds to the source
  • Eventually, BGWorker 2 Wakes up and Binds the DataGridView source to the modified Source
  • Dll threads keep parsing but fails once it tries to add a new element to the source

TL:DR:
Thread 1 Writes on the Source
Thread 2 Reads this modified source, and binds it to the DataGridView to it will refresh
Thread 1 Fails to write again on the source :

"Cross-thread operation not valid: Control 'CoursesGrid' accessed from a thread other than the thread it was created on."}

Both threads are handling the same source, but the BGWorker 2, only binds it to the interface, this should be working. Any idea of what might be happening here?

  • 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-06T01:31:48+00:00Added an answer on June 6, 2026 at 1:31 am

    I think what is happening is that you are binding the data grid to your _coursesSource which causes the data grid to show the first row. Then, later, you are modifying the same _coursesSource instance which likely fires a property change or collection change notification which causes the data grid to attempt to update itself (ie. show the newly added row).

    But since the modification is happening on another thread the event which the data grid “hears” and responds to also happens on that background thread which causes the cross thread violation.

    What you need to do, is either a) marshal the add to _coursesSource onto the UI thread (which it doesn’t sound like you can easily do), or b) bind to a copy of _coursesSource and then in your BGWorker 2, each time you update _coursesSource re-bind the grid to a new copy, that way the grid is never “hearing” change notifications, it’s always just binding to a fresh copy of the collection. It’s not the most efficient way to do things, but it should get the job done for you.

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

Sidebar

Related Questions

Goal: Once clicking on add or delete button, the datagridview should be refreshed with
So my goal is once a user clicks on the item from the dropdown
Goal: I have a thumbnail as a byte array in memory. Once a user
Goal To use a CREATE TYPE statement in HSQLDB 2.0.0 to create a user-defined
goal : I want to place a text after the submit button using hook_form_alter.
Goal : After user saves data to my mysql DB, a JSON teaser of
Goal: I'm trying to refresh content inside a div so that if the user
I'm trying to add a class to an li element once after button is
Goal: Allow user to select one or more images from his photo library. Get
Please see my code below. The goal is the following. When a user presses

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.