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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:41:43+00:00 2026-05-26T19:41:43+00:00

Is there a better way to do this function? Even though i’m doing the

  • 0

Is there a better way to do this function? Even though i’m doing the actual query inside of a background workder, there is a bit of a slight pause in the application as the query is taking place, so was wondering if there was a faster way of doing this.

Essentially, the queries are checking the dataset for unique results from specific columns, to populate a comboBox with those items. This lets us not have to hard code any options into the filters, and if we add items on the server for those values, they are added when the next time the dataset is updated automatically.

I’m just not sure if the methods i’m using could be done in a shorter, quicker format:

private IEnumerable<string> queryStatus;
private IEnumerable<string> queryPriority;
private IEnumerable<string> queryCompany;
private IEnumerable<string> queryCategory;

private void filterBuilder_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
   {
       Console.WriteLine(DateTime.Now.ToString());
       DataTable demoCriteria = Ds.Tables[1];
       queryStatus = (demoCriteria.AsEnumerable().Select(row => row.Field<string>("ows_Status"))).Distinct();
       queryPriority = (demoCriteria.AsEnumerable().Select(row => row.Field<string>("ows_Priority"))).Distinct();
       queryCompany = (demoCriteria.AsEnumerable().Select(row => row.Field<string>("ows_Company"))).Distinct();
       queryCategory = (demoCriteria.AsEnumerable().Select(row => row.Field<string>("ows_Category"))).Distinct();
   }

private void filterBuilder_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
   {
       foreach (string row in queryStatus)
       {
           if (!viewFilter_Status.Items.Contains(row))
               viewFilter_Status.Items.Add(new ComboBoxItem(row,
                                                           row));
           if (!editStatus.Items.Contains(row))
               editStatus.Items.Add(new ComboBoxItem(row,
                                                     row));
           if (!newStatus.Items.Contains(row))
               newStatus.Items.Add(new ComboBoxItem(row,
                                                    row));
       }
       foreach (string row in queryPriority)
       {
           if (!viewFilter_Priority.Items.Contains(row))
               viewFilter_Priority.Items.Add(new ComboBoxItem(row,
                                                              row));
           if (!editPriority.Items.Contains(row))
               editPriority.Items.Add(new ComboBoxItem(row,
                                                       row));
           if (!newPriority.Items.Contains(row))
               newPriority.Items.Add(new ComboBoxItem(row,
                                                      row));
       }
       foreach (string row in queryCompany)
       {
           if (!viewFilter_Company.Items.Contains(row))
               viewFilter_Company.Items.Add(new ComboBoxItem(row,
                                                             row));
           if (!editCompany.Items.Contains(row))
               editCompany.Items.Add(new ComboBoxItem(row,
                                                      row));
           if (!newCompany.Items.Contains(row))
               newCompany.Items.Add(new ComboBoxItem(row,
                                                     row));
       }
       foreach (string row in queryCategory)
       {
           if (!viewFilter_Product.Items.Contains(row))
               viewFilter_Product.Items.Add(new ComboBoxItem(row,
                                                             row));
           if (!editProduct.Items.Contains(row))
               editProduct.Items.Add(new ComboBoxItem(row,
                                                      row));
           if (!newProduct.Items.Contains(row))
               newProduct.Items.Add(new ComboBoxItem(row,
                                                     row));
           }

       MainFormCallbacks.EnableISTab(true);
   }
  • 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-26T19:41:44+00:00Added an answer on May 26, 2026 at 7:41 pm

    You’re not actually doing the work in the background thread – you’re just preparing it. Calling Distinct() only builds an IEnumerable<T> which will yield distinct items when you iterate over it. You’re not iterating over it until the “completed” method, which will be back in the UI thread.

    It’s entirely possible that you can get rid of the delay by forcing the query to be executed in the background thread, like this:

     queryStatus = demoCriteria.AsEnumerable()
                               .Select(row => row.Field<string>("ows_Status"))
                               .Distinct()
                               .ToList(); // Note this call!
    

    (and the same for the other values, obviously).

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

Sidebar

Related Questions

Is there a better way of getting this result? This function fails if num
Is there a better way of doing this ? SELECT (SELECT count(*) FROM `tbl`
Is there any better way to make this query work? I'm looking for a
Is there a better way than this to splice an array into another array
Is there a better way than this to determine the row a user double-clicked
Is there a better way to do this? -(NSDate *)getMidnightTommorow { NSCalendarDate *now =
Is there a better way to write this code? I want to show a
Is there a better way to do this? string[] s = {zero, one, two,
Is there a better way to do this? I have an HTML helper extension
Is there a better way to do this jquery code? Currently I have to

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.