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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:51:38+00:00 2026-05-10T17:51:38+00:00

I’m trying to do some async stuff in a webservice method. Let say I

  • 0

I’m trying to do some async stuff in a webservice method. Let say I have the following API call: http://www.example.com/api.asmx

and the method is called GetProducts().

I this GetProducts methods, I do some stuff (eg. get data from database) then just before i return the result, I want to do some async stuff (eg. send me an email).

So this is what I did.

[WebMethod(Description = 'Bal blah blah.')] public IList<Product> GetProducts() {     // Blah blah blah ..     // Get data from DB .. hi DB!     // var myData = .......     // Moar clbuttic blahs :)  (yes, google for clbuttic if you don't know what that is)      // Ok .. now send me an email for no particular reason, but to prove that async stuff works.     var myObject = new MyObject();     myObject.SendDataAsync();      // Ok, now return the result.     return myData;     } }  public class TrackingCode {     public void SendDataAsync()     {         var backgroundWorker = new BackgroundWorker();         backgroundWorker.DoWork += BackgroundWorker_DoWork;         backgroundWorker.RunWorkerAsync();         //System.Threading.Thread.Sleep(1000 * 20);     }      private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)     {         SendEmail();     } } 

Now, when I run this code the email is never sent. If I uncomment out the Thread.Sleep .. then the email is sent.

So … why is it that the background worker thread is torn down? is it dependant on the parent thread? Is this the wrong way I should be doing background or forked threading, in asp.net web apps?

  • 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. 2026-05-10T17:51:39+00:00Added an answer on May 10, 2026 at 5:51 pm

    BackgroundWorker is useful when you need to synchronize back to (for example) a UI* thread, eg for affinity reasons. In this case, it would seem that simply using ThreadPool would be more than adequate (and much simpler). If you have high volumes, then a producer/consumer queue may allow better throttling (so you don’t drown in threads) – but I suspect ThreadPool will be fine here…

    public void SendDataAsync() {     ThreadPool.QueueUserWorkItem(delegate     {         SendEmail();     }); } 

    Also – I’m not quite sure what you want to achieve by sleeping? This will just tie up a thread (not using CPU, but doing no good either). Care to elaborate? It looks like you are pausing your actual web page (i.e. the Sleep happens on the web-page thread, not the e-mail thread). What are you trying to do here?

    *=actually, it will use whatever sync-context is in place

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

Sidebar

Ask A Question

Stats

  • Questions 109k
  • Answers 109k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Abstraction. If you're dependent on this 3rd party API, I… May 11, 2026 at 9:22 pm
  • Editorial Team
    Editorial Team added an answer If you're running on IIS7 integrated mode (which I suggest… May 11, 2026 at 9:22 pm
  • Editorial Team
    Editorial Team added an answer You haven't enclosed the text in quotes in the resulting… May 11, 2026 at 9:22 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.