?
Solved

windows service, multithreaded programming

Posted on 2011-09-02
5
Medium Priority
?
275 Views
Last Modified: 2012-05-12
I have a timer in my windows service which checks database every 5 minutes and if there are any entries, it reads those and with that data it performs a HTTPS Post request to a 3rd party. Due to restrictions from 3rd party i can only include only 20 entries from the database and include it in one request. However, i can send request every 10 seconds but i have to make sure i receive a response, before i send another one. Right now it makes request to the 3rd party every 5 minutes,
but i want to change it so that it can send request with a dealy of 10 seconds for every request
but at the same time making sure that i receive a response before i send another one. So, the service needs to check database every 5 minutes, but every time it checks it and if there is data, say more than 20, it needs to take first 20 and do a request, get a response and send another request. any suggestions?
0
Comment
Question by:singsunn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 36475002
how much data will you receive from the database ? (max)

do you need to requery the database to get the next 20 to send?
or can you send the next batch directly from the first set returned by the database
after the 10 second wait ? (e.g. is there a "Freshness factor for the data")

what else is using the database?

what happens when you don't get a response from the third party (or it returns after the 10seconds)?
0
 

Author Comment

by:singsunn
ID: 36475126
Since i can submit 20 in one post, i am using a  stored procedure to select top 20 from the table. and this happens with a timer which is fired every 5 minutes.  but this is little bottleneck because i can submit 20 every 10 seconds. So basically i requery the table every 5 minutes.
I want to select 100, if present, every 5 minutes and select 20 from that and do a post to 3rd party every 10 secs.
About not getting the response back, (in case of connection error) i basically log any kind of exceptions.
after elapsed time it will try to do a request again.
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 36475371
so do you send the same 20 each time?
how do you exclude those you've already sent/queued?
0
 

Author Comment

by:singsunn
ID: 36475439
Select top 20, process them and send them. once i receive response for those i select the same 20 and delete from the table.
0
 
LVL 1

Accepted Solution

by:
ananken earned 2000 total points
ID: 36511543
I'd do something like this:
- In the timer you currently have select top 600 instead of top 20 (that's how many top 20 there are in case performing the query every 10 secs for 5 minutes).
- Break up your results to groups of 20's and enqueue them to a Queue<> object.
- Set up another timer (or worker thread) which will monitor this queue every 10 seconds. Once it finds results in the queue, it should dequeue the 1st results and then send it to the 3rd party and wait for the results.
- It can also perform a retry in case of failure.
- Delete the results from the DB after send is successful.
- The other timer (or worker thread) should wait for the to be empty before performing the next query. (This can be accomplished using Monitor.Wait / Monitor.PulseAll).

Hope this helps,
ananken.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Make the most of your online learning experience.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Introduction to Processes

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question