Click here to Skip to main content
13,446,260 members (35,263 online)
Rate this:
Please Sign up or sign in to vote.
Hi there,

I have a WCF webservice that executes a function that could take around 10 seconds to complete.

The client can call the WCF web service asynchronously by either executing the WCF calls via a thread pool, or using the generated asynchronous methods.

However I would like to execute the functions async AS WELL as concurrently, ie many calls to the same web service to be called very shortly after each other.

So for example wcf call 1 is initiated at 00:00
wcf call 2 is initiated at 00:01, then call 3 at 00:02 etc. They should complete at 00:10 then 00:11 and 00:12.

In the above examples. The web sservice is called asynch but executed sequentially, so call 1 is executed, 10 seconds late call 2 is executed and so forth.

I have change the max connection values, but to no avail.

I notice that if I create the WCF service function as a threaded function within the web service, i get the desired effect, ie "wcf call 2 is initiated at 00:01, then call 3 at 00:02 etc. They should complete at 00:10 then 00:11 and 00:12".

But is this really the way it should be done, is there any alternatives, that are "neater"?
Posted 12-Sep-11 9:58am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

My opinion is: all asynchronous calls dominated well threading was not introduced or well established. I don't see situation when those could beat threads. Threads are easier to implement as in a single thread all logic is sequential, they are well equipped with thread synchronization primitives and are ultimately more reliable is used properly.

The relatively costly operation of thread creation could be compensated by using thread pools or, better yet, by using "permanent threads" (threads with life time nearly the same of that of the whole process) throttled by thread synchronization and reused for repeated task.

I offer a very regular way of such throttling via a blocking message queue; see my Tips/Trick article: Simple Blocking Queue for Thread Communication and Inter-thread Invocation[^].

Please take a look at my past solutions on this and related topics:
How to get a keydown event to operate on a different thread in[^],
Control events not firing after enable disable + multithreading[^].


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180314.2 | Last Updated 12 Sep 2011
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100