Click here to Skip to main content
Rate this: bad
good
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
faroukg130

1 solution

Rate this: bad
good
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 vb.net[^],
Control events not firing after enable disable + multithreading[^].
 
—SA
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 505
1 OriginalGriff 258
2 ChintanShukla 195
3 Bhavik_Patel 170
4 Richard Deeming 165
0 Sergey Alexandrovich Kryukov 8,688
1 OriginalGriff 7,237
2 CPallini 2,598
3 Richard MacCutchan 2,080
4 Abhinav S 1,888


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 12 Sep 2011
Copyright © CodeProject, 1999-2014
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