473,402 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 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 918

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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.