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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:11:52+00:00 2026-05-23T06:11:52+00:00

I have a task that I perform in parallel; for instance printing user selected

  • 0

I have a task that I perform in parallel; for instance printing user selected documents async’ly. One way may be to use a worker thread. But thinking of the scenario where thousands of requests pouring in onto the web server, and application is spawning one more thread for printing sounds horrible. And what if all of the concurrent users start printing?

So is the reason I want to avoid worker threads.

To work around, I have moved the code in a web service; I am calling the PrintAsync() method, and I have subscribed to OnPrintComplete to get notified. Now I can send as many prints as I want without worrying about asp.net thread starvation or blocking requests.

I know web services internally use threading, but that is IOCP threads, which means it will not bother the asp.net worker threads.

I couldn’t think of possible cons, except that it will be a web service.

Is this a good approach? What would have been a better alternate version of handling this functionality?

  • 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-23T06:11:53+00:00Added an answer on May 23, 2026 at 6:11 am

    So you’ve described how you’re making async calls on the client and there’s actually some more questions I would ask about how you’re actually being completely async there, but it seems like your question is more about how to be as efficient as possible on the service side, right?

    If you’re performing long running or I/O bound operations in your service operations, you absolutely must begin to leverage WCF’s support for asynchronous service operations. Now, there’s lots of ways to do this, but if you’re on .NET 4.0 there’s no better way than using the Task Parallel Library (TPL).

    First, by offloading the work to a TPL thread you free up WCF I/O threads to handle more calls. This way your long running WCF operations don’t tie up WCF’s ability to field other operations.

    Second, the TPL leverages the a thread pool by default. You don’t have to worry about every operation spinning up it’s own thread and eventually starving the machine of resources. The TPL is also smart enough to spread the work across all the cores on the box way more efficiently than you could ever do yourself without a significant investment in writing plumbing code.

    Third, the TPL can be combined with the traditional Asynchronous Programming Model (APM) so that if you’re working with things like Streams (network or file) you can use their BeginRead/Write methods to leverage async I/O to the max which will free up the CPU threads while blocking on reads/writes. You should absolutely be doing this to achieve maximum efficiency even if you’re not using the TPL, the TPL just makes it easier.

    Here’s a “bare bones” example of how you can use the TPL to implement an async service operation:

    public IAsyncResult BeginSomeLongRunningOperation(string sampleParam, AsyncCallback callback, object asyncState)
    {
        Task<int> processingTask = Task<int>.Factory.StartNew(
            _ =>
            {
                 ... perform insanely long running operation here ...
    
                 return 42;    
            },
            asyncState);
    
        // If there was a callback, we have to invoke it after the processing finishes
        if(callback != null)
        {
            processingTask.ContinueWith(
                _ =>
                {
                    callback(calculationTask);                   
                },
                TaskContinuationOptions.ExecuteSynchronously);
        }
    
        return processingTask;
    }
    
    public int EndSomeLongRunningOperation(IAsyncResult asyncResult)
    {
        return ((Task<int>)asyncResult).Result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MDI WinForms application that can perform several tasks. Each task is
I have a task I need to perform, do_stuff(opts) , that will take ~1s
I have a task that I need to perform for a friend as a
I have a computationally intensive task that users can perform using a Silverlight app.
I have a data flow task that extracts data from one database and inserts
I am trying to perform a task that may not be possible. I haven't
I have a long-running Task that I've implemented using the Task Parallel Library. When
I have an Ant script that performs a copy operation using the 'copy' task
I have a task that takes a rather long time and should run in
I have a Task object that has a collection of Label objects ... in

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.