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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:18:23+00:00 2026-05-24T21:18:23+00:00

I know this question has been asked here before, but I’ve read through several

  • 0

I know this question has been asked here before, but I’ve read through several answers that haven’t helped me.

I have a ComboBox that needs to get some information related to a selection from a database (probably on lost focus, to stop a thousand calls during scrolling). This information is for display only, and not critical, so getting on a background thread/task sounds like the perfect solution. It does take several seconds though, as it is getting counts from some very large tables. The user should be free to move on to other tasks, as this information really is just for display/reference only.

This question advocates using a Background worker, but this solution has two issues. 1) Changing the selection while the worker is already running introduces problems. You can either not start it the second time, meaning when it returns it is no longer showing valid info for the new selection, or try to cancel it (which doesn’t always work). 2) For some reason I cannot explain, the method that actually accesses the database for the background worker returns slower if the method is in Model than if in the ViewModel, where I do not think it belongs. I really don’t know why.

This question has several votes, but the OP’s question is worded very poorly, and the selected answer just says “yeah that should work.”

This question’s method looks promising, but the linked video is an hour long (I watched the whole thing), and touches on the dispatcher only for 10-15 seconds without explaining it. If someone has a link to an article that covers this method more in-depth, that would be good.

Thread pooling, as suggested here looks like it is probably the best way to go, as multiple requests for lookup just get queued, instead of causing already-running errors. However, it has no explanation of how to use a thread pool, instead linking to the MSDN article. If someone has a link to an article that covers this method more in-depth, that would be ideal, as it seems like the better solution (of course, I could be wrong).

I really tried to do my research on this one, but most of these answers just tell you what method to use, not how to use it. I am really looking for a “how-to.”

  • 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-24T21:18:24+00:00Added an answer on May 24, 2026 at 9:18 pm

    OK. Your question:

    1. You have a selection control with list of items
    2. You have an expensive operation that returns some result from the currently selected item (Note that this operation should be expensive, not just takes time to return, in order to have you worry about not having too many of them at the same time) — so you need to do it in parallel
    3. The returned result is not acted upon, only displayed — so do it asynchronously
    4. If the currently selected item changes, you no longer want the previous result — and the previous requests should be cancelled as soon as possible because they are expensive

    What you should do, with the latest .NET technologies:

    1. Use Reactive Extensions (Rx), set up a throttle so that it only fires when the user keeps the current selection for, say, at least 500ms (you don’t want to spawn many many taks when the user keeps pressing the down arrow key)
    2. When the throttle fires, call an async method (Async CTP) which await the operation in a Task (long-running to avoid starving the thread pool), and also put in a Cancellation token; save the current selection for comparison later
    3. When the operation returns, set the result into your data context (which your display control should be bound to) — the async method always continues on the UI thread, so you don’t have to worry about thread access
    4. If the throttle fires and there is an outstanding task / cancellation token, first use the cancellation token to cancel the task, before spawning a new task as per #2. The await will throw because the Task is cancelled, but it doesn’t matter since you don’t need it any more.
    5. There is no concurrency issues here because the Async CTP always continues on the UI thread. As far as all your operations are concerned, they are all single-threaded and won’t tread on each other.

    I think if you use the Async CTP with Rx, it is about 10 lines of code.

    Note: If your operation is NOT EXPENSIVE, you don’t have to use a cancellation token. Just allow the task to run to completion, but ignore the result. However, it is still recommended that you cancel a database query early, although it is not expensive on the client machine, it is expensive on the server.

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

Sidebar

Related Questions

I know this question has been asked here before, but I don't think those
I know this question has been asked before and I read all the answers
I know this question has been asked here a few times before. But i
Folks, I know this question has been asked before here, though indirectly . But
I know this is a question that has been asked before, but I think
I know that this question has been asked before, but I'm looking for a
I know this is a question that has been asked many times before, but
I know this question has been asked before, but I ran into a problem.
I know this question has been asked a bit before. But looking around I
I know this specific question has been asked before , but I am not

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.