Solved

windows service, multithreaded programming

Posted on 2011-09-02
5
270 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 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create .bat File 16 74
IDE for Python 5 74
locate sql commands in C# visual studio Project 6 45
SQL works but want to get the XML node data separately 11 31
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

730 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