473,856 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
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? BackgroundWorke rs?
3. Do i use one BackgroundWorke r 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 942

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

Similar topics

8
1905
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 requirements of Forms). Is there a way to build Chat like application WITHOUT using FORM, so that one can use free threading model (The link...
4
2979
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 for the changes, and then generates a report using the VS.NET 2003 version of Crystal Reports, and prints the report. It works just fine when I use it in a single threaded environment. However, when I build an application that uses a...
6
555
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 and the final process(3) gets called. what am I doing wrong with the threading? by the way Directory.GetFiles(IncomingXMLPath1).Length is some global outcome from process 1. Thanks 1)
4
285
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 problem is if the files in process 1) are all processed and we are in the middle of process 2) , at this point if i coppy a file to the directory for process 1) then this file never gets processed and we never enter process 3) . How can I fix this...
2
13224
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 System.Timers.Timer but i had to remove it because of known bug(842739). Now i am using System.Threading.Timer. It executes routine fine but the delay time is sporadic, sometimes it executes routine after 5 minutes, sometimes 10 minuete, 13...
1
2472
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 again do the processting.... This is because my main process should transfer the load to different threads, if any thread is free then ask that tread to do the job, else create a new thread and do the job...
17
6446
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. Note, the Windows task manager shows 2 CPUs on the Performance tab with hyper-threading is turned on. Both Python 2.3.5 and 2.4.3 (downloaded from python.org) have this problem. The operating system is MS Windows XP Professional.
0
1037
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 code if I create a Windows form application. Also what would be the diferrence between the threading model of Windows forms and ASP.NET. Please enlighten.
19
1819
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. Threading is a new concept for me to implement. Here is my problem. I have a system that receives xml files and records their file locations in a database. I can potentially receive thousands,
0
9918
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11060
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10697
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10786
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10389
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9532
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5959
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4578
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3202
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.