![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello, I currently have a windows service which handles multiple threads and a shared queue object in which I had jobs to process. Now I would like to be able to add jobs on the windows service queue trough a .net remoting call. I had a look at .net remoting documentation but i'm not experienced with it so I'm not sure how to achieve what I want. Below is a shortened sample of my code. Should i make a method in program which returns my static jobQueue to call AddJob on it or maybe I can build a delegate to call jobQueue.AddJob() whithout exposing the class ? Any help is welcome Kind regards Gilles Here is a sample of the windows service code : - The program class is the main class of my service - The jobQueue is a static instance of InputOutputProducer and is used among different threads to manage the queue trough the AddJob() and DequeueJob() methods which are threadsafe. - Each thread runs individually, builds jobs and then add them to the Queue trough Program.jobQueue.AddJob() ; - What I want to do is to be able to call the AddJob method of my existing jobQueue from a website using .NET Remoting. I think I need to make a singleton SAO but i'm a bit stucked to build public class Program { public static InputOutputProducer jobQueue; public static void Start() { jobQueue = new InputOutputProducer(); new Thread(new ThreadStart(EnqueueFTP)).Start(); new Thread(new ThreadStart(EnqueueMailPuller)).Start(); while (true) { // Dequeue Job Job job = (Job)jobQueue.DequeueJob(); // Process Job ProcessJob(job) ; } } /// <summary /// Starts FTPWatcher Thread /// </summary public static void EnqueueFTP() { FTPWatcher ftpWatcher = new FTPWatcher(); } /// <summary /// Starts MailWatcherThread /// </summary public static void EnqueueMailPuller() { MailPuller pullMail = new MailPuller(); } } public class InputOutputProducer { readonly object listLock = new Object(); Queue queue = new Queue(); public void AddJob(Job job, Enums.Threads currentThread) { // Lock Queue while Enqueuing lock (listLock) { queue.Enqueue(job); Monitor.Pulse(listLock); } } public object DequeueJob() { // Lock Queue while Dequeuing lock (listLock) { // If the queue is empty, wait for an item to be added // Note that this is a while loop, as we may be pulsed but not wake up before another thread // has come in and consumed the newly added object. In that case, we'll have to wait for another pulse. while (queue.Count == 0) { // Release listLock until woken up by Pulse Monitor.Wait(listLock); } return queue.Dequeue(); } } } } |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |