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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:37:40+00:00 2026-05-28T06:37:40+00:00

I am using BackGround Worker for Loading data from DB(MS Access). In my Form_Load

  • 0

I am using BackGround Worker for Loading data from DB(MS Access).
In my Form_Load i use:

 bgw.RunWorkerAsync();

In my DoWork event I laod the data from DB

private void bgw_DoWork(object sender, DoWorkEventArgs e)
    {

        int iResult = OpenDB();
        if (iResult != 0)
        {
            MessageBox.Show("Error in Opening DataBase", Constants.TITLE);
            return ;
        }
        DataSet ds = GetAllUserInfo();
        e.Result = ds;


    }

And in My RunWorkerCompleted i assign data to DataGridView.

    private void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {

        dgUsers.Rows[0].Cells[0].Value = e.Result; 


    }

//Error Comes here after executing above code

[STAThread]
        static void Main()
        {
            Application.Run(new frmMain());
        }

Any help is appreciated.
Thanks.

  • 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-28T06:37:41+00:00Added an answer on May 28, 2026 at 6:37 am

    Use SyncronizationContext mechanism for UI update . Example here http://www.codeproject.com/KB/threads/SynchronizationContext.aspx

    1 .Have this as a global object :

    System.Threading.SynchronizationContext synchronizationContext;
    
    1. Instantiate the object “synchronizationContext” on Form_Load event :

      synchronizationContext = System.Threading.SynchronizationContext.Current;

    2. Modify bgw_RonWorkerCompleted to :

      private void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
      {

            synchronizationContext.Post(new SendOrPostCallback(
             delegate
             {
                 dgUsers.DatSource =e.Result as DataSet;
             }), null);
      

      }

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

Sidebar

Related Questions

View model is loading data asynchronously using background worker thread in model. All properties
I'm using a background worker in order to get data from a database. My
What happens to the data that is passed to and from a background worker?
i am using the background worker to do an expensive operation: backgroundWorker1.DoWork += new
C# 2008 SP1 I am using the background worker If one of the conditions
I am using the Background worker thread in a Silverlight 4 application. In the
Let's say I have a background worker like this: private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs
I have a treeview using BackGround worker to add nodes when you expand any.
what is the difference between create thread using thread.start and using background worker ?
C# 2005 I am using a background worker to process some login information. However,

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.