0
I was thinking of a similar solution. I decided to try my first attempt at a Producer/Consumer setup bc it seemed to fit what I am doing. instead I changed to synchrnous calls though.
I think I am getting a deadlock when attempting to lock in the Enqueue method right off the bat ... based on my reading ... I shouldn't be getting this issue since I obtain the lock by default the first time and make sure to wake other threads as well while in the lock
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using WinDriverService.PWS;
namespace WinDriverService
{
public class ProducerConsumer
{
private readonly object listLock = new object();
public enum ServiceType
{
Weather,
WeatherAlert,
EqAlert,
TsunamiAlert,
FloodAlert
};
private Queue<ServiceType> queue;
private PollingWebService pws;
public ProducerConsumer()
{
queue = new Queue<ServiceType>();
pws = new PollingWebService();
pws.Timeout = 600000;
}
public void Produce(ServiceType item)
{
lock (listLock)
{
queue.Enqueue(item);
Monitor.Pulse(listLock);
}
}
public PollerEntry[] Consume()
{
PollerEntry[] entries = null;
lock (listLock)
{
while (queue.Count == 0)
{
Monitor.Wait(listLock);
}
ServiceType type = queue.Dequeue();
if (type == ServiceType.Weather)
{
entries = pws.PollWeatherInfo();
}
else if (type == ServiceType.WeatherAlert)
{
entries = pws.PollWeatherAlerts();
}
}
Monitor.Pulse(listLock); //wake any threads waiting in this method to obtain lock
return (entries);
}
}
}

0
Have you tried creating a thread specifically for sending the webservice requests from a queue and then have your timers simply populate this queue?