private static void SearchAndListen()
{
while (true)
{
searching.WaitOne();
try
{
var enabledProtocols = EnabledProtocols.ToList();
if (enabledProtocols.Contains(UpnpSearcher.Instance.Protocol))
{
Receive(UpnpSearcher.Instance, UpnpSearcher.sockets);
}
if (enabledProtocols.Contains(PmpSearcher.Instance.Protocol))
{
Receive(PmpSearcher.Instance, PmpSearcher.sockets);
}
foreach (ISearcher s in controllers)
if (s.NextSearch < DateTime.Now && enabledProtocols.Contains(s.Protocol))
{
Log("Searching for: {0}", s.GetType().Name);
s.Search();
}
}
catch (Exception e)
{
if (UnhandledException != null)
UnhandledException(typeof(NatUtility), new UnhandledExceptionEventArgs(e, false));
}
Thread.Sleep(10);
}
}