Solved

windows service, multithreaded programming

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

707 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