472,377 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,377 software developers and data experts.

Which threading model to use for a C# windows service?

Hello.

I'm facing a bit of an annoying indecision regarding the design of a particular component of my solution.

Perhaps there's someone who can offer some experience/creative insight into it?

Here's my scenario: I'm buiding a windows service that calls an xml web service and deals with the responses appropriately. this 'service agent' picks messages from a transactional message queue one at a time, attempts the web call, if it fails, raises the priority of the message and puts it back in the queue. It does this a certain number of pre-configured times before failing completely and notifying the user. I've realized though, that the time it takes per web call could vary, depending on the type of request. So my answer to this was to have multiple instances of the service agent running on separate threads, that each processes the next message in the queue when they are available, so if one web call gets held up, another thread can continue processing requests. I've tested and this works fine in principal, but the design decision i need to make is this:

1. Do i use the .net ThreadPool class with an array of waithandles to create the threads?
2. Do i use an array of instantiated Thread objects? BackgroundWorkers?
3. Do i use one BackgroundWorker to read the next message off the queue which fires off the processing thereof on a separate thread? (if so, how do i limit the number of concurrent threads?)
4. Is there a better way to do this, bearing in mind my intention is to have a small number of threads each running 1 method that (theoretically) never ends?

I have managed to use threading pretty efficiently in the past, but I want to implement the optimum solution here as resources and uptime are both critical.

Any input appreciated.
Dave
Dec 4 '07 #1
0 875

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Mahesh Devjibhai Dhola [MVP] | last post by:
We are building Chat like application using Forms and as a result our programming is becoming complicated to display messages received on different threads in the chat window (due to STA...
4
by: Ryan Gregg | last post by:
I've got a background service running that needs to check a database periodically and print reports whenever it finds that the data has changed. I've built a class library that scans the database...
6
by: CK | last post by:
I have the following code in a windows service, when I start the windows service process1 and process2 work fine , but final process (3) doesnt get called. i stop and restart the windows service...
4
by: CK | last post by:
I have the following code in a windows service, when I start the windows service process1 and process2 work fine ,When process 1) and 2) get completed process 3) starts and sofar so good. the...
2
by: linesh.gajera | last post by:
Hi Guys, I am creating a Windows service that call a routine at given interval. Once routine is complete, windows service should wait for 5 minutes and then call the routine again. I was using...
1
by: SMG | last post by:
I m looking out for some examples on Windows Service and Threading Model. Main Process Calls Thread1 Main Process checks whether Thread1 is busy then it creates second thread second thread...
17
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
0
by: Carly | last post by:
Hi, I am not sure I understand what is the meaning of "Execution of asynchronous code is not supported in Windows Forms threading model" - since I am able to create threads and run asynchronous...
19
by: frankiespark | last post by:
Hello all, I was perusing the internet for information on threading when I came across this group. Since there seems to be a lot of good ideas and useful info I thought I'd pose a question. ...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.