Solved

windows service, multithreaded programming

Posted on 2011-09-02
5
262 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
  • 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 500 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video teaches users how to migrate an existing Wordpress website to a new domain.
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 …

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now