[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

windows service, multithreaded programming

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
singsunn
Asked:
singsunn
  • 2
  • 2
1 Solution
 
LowfatspreadCommented:
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
 
singsunnAuthor Commented:
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
 
LowfatspreadCommented:
so do you send the same 20 each time?
how do you exclude those you've already sent/queued?
0
 
singsunnAuthor Commented:
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
 
anankenCommented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now