Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
5.00/5 (1 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

1 solution

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 vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900