Click here to Skip to main content
15,846,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am designing a solution for a client where in data has to be polled from SQL table and a request is to be sent to a WCF service with a request formed from that data. The response of the WCF service will contain additional data that has to be updated in the SQL table again.

For e.g. in TableA there are 6 columns namely primaryKeyColumn,columnA, columnB, columnC, columnD and columnE.

The WCF request will contain data from columns A,B and C.
The service response will contain data for all 5 columns.
The data of columns D and E needs to be updated for that row in the tableA.

I have thought of implementing this using Windows service. To increase the performance I am thinking to implementing multi threading in this solution.

Can some one guide me in this ? I have never used multi threading in windows service before. What are the risks ?

What I have tried:

I have created a windows service that polls the SQL database table every 15 seconds,gets the first row depending on certain condition,create the request for WCF service , call the WCF service, update the data in SQL table based on the response.
I have not implemented multi threading yet.
Updated 15-Nov-16 22:58pm

1 solution

A windows service basically has to be multithreaded if it wants to be able to do anything at all. The basic pattern (much of which is stubbed for you when you create a Windows Service) is that the main thread handles commands from the service controller (Start, Stop, Pause, and the like). The normal pattern is when the "Start" command goes through, you start off a thread that waits for some sort of IPC from your app. Included in that wait are also signals from the main thread to pause or stop the service. When an IPC comes through, depending on the sort of processing involved in the command, you can either process the command in that thread (if it's quick), or kick off another thread to process the command (if it's possible to get another command before the first is finished processing).

All the normal rules of threading apply - interrupting the processing, protecting data, etc. The only thing you don't have to worry about is marshalling to the UI thread, as there is none.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900