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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:03:35+00:00 2026-06-15T10:03:35+00:00

[Windows forms application & .NET 4.0] I need to execute database access methods that

  • 0

[Windows forms application & .NET 4.0]

I need to execute database access methods that return objects (either list of classes or simple classes).

Also i need to open forms that are responsive while main thread does initialization.

I need to run these on separate threads keeping the User Interface responsive and of course to be able to pass the results back to main thread for UI updates.

I have been reading books regarding the various ways for this.

I understand that my job can be done by:

  • BackGroundWorker
  • Thread Class
  • Task Class

Which one i should dive into ?

Update: using the suggested Task class i am getting errot for cross thread safety using this:

private void BtnCheckClick(object sender, EventArgs e)
{
    var itm =   Task<JDEItemLotAvailability>.Factory.StartNew(() =>
                             Dal.GetLotAvailabilityF41021(
                                                         txtLot.Text,
                                                         cmbMcu.SelectedItem.ToString(),
                                                         cmbLocn.SelectedItem.ToString())
                            );
       lblDescriptionValue.Text = itm.Result.Description;
       lblItemCodeValue.Text = itm.Result.Code;
       lblQuantityValue.Text = itm.Result.AvailableQuantity.ToString();
       LotFocus(true);
}

On the above exmaple i am getting the exception in cmbMcu control not the txtLot.

  • 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-15T10:03:36+00:00Added an answer on June 15, 2026 at 10:03 am

    I would use the Task class, it’s really easy to synchronize it and it already provides a support for returning objects.

    var task = Task.Factory.StartNew(
        () => GetDatabaseData(someArguments),
        TaskCreationOptions.LongRunning);
    
    // Example method
    public DataSet GetDatabaseData(object args) { ... }
    

    this this tells a scheduler to create and begin a new task and gives it a hint that it might be a good idea not to use a thread-pool thread, if the scheduler uses a thread-pool. Anyway you can now decide how do you want to synchronize.

    For example to achieve similar behaviour as in Gregor Primar’s answer, you can set up a continuation using ContinueWith method as follows,

    task.ContinueWith(oldTask => ProcessReturnedData(oldTask.Result));
    
    // Example method
    public IEnumerable<SomeEntity> ProcessReturnedData(DataSet data) { ... }
    

    which will schedule calling the ProcessReturnedData method after the task object has done executing. Note that this will be called even if task fails for some reason, so it may not be always a good solution – or you would have to do some checks in the provided delegate.

    If you want to do a non-blocking wait on the main thread and use the returned object there, you can simply use the Wait method.

    task.Wait(); // Makes current thread wait until the task is comnpleted.
    DataSet result = task.Result; // Accessing the result object.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MDI Windows Forms application (.net 2008) that allows the user to
I created a windows forms application in C #, and a database MS SQL
I have a windows forms application in .NET 3.5. There's one form with 20
I have a windows forms application that reads and updates an XML file with
I have a Windows Forms application that on it I have a RichTextBox, like
I have a Windows Forms application in C# .NET. It contains a user-drawn control
I have a Windows Forms application that uses some Application.Idle handlers to change the
I'm developing C# .NET windows Forms application. In which I've a main window and
I am using a Microsoft Chart control (system.windows.forms.datavisualization.charting.chart) in a Windows forms application, vb.net
I have a Windows Forms application in .NET 2.0 with a PictureBox on a

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.