All pastes #464111 Raw Edit

Miscellany

public text v1 · immutable
#464111 ·published 2007-04-29 10:09 UTC
rendered paste body
		private static object sync = new object();
private static void Watcher()
		{
			do
			{
                              lock(sync)
                              {
				if (DownloadQueue.Count > 0)
				{
					NzbSegment Segment = null;
					foreach (NzbSegment s in DownloadQueue)
					{
						if (!DownloadingQueue.ContainsKey(s))
						{
							Segment = s;
							break;
						}
					}

					foreach (Connection Connection in Connections)
					{
						if (Connection.Status == ConnectionStatus.Idle)
						{
							DownloadQueue.Remove(Segment);
							ArsiaLog.Log(LogEntryType.Debug, "Removed: {0}", Segment.MessageId);
							FileStream Stream = new FileStream(Path.Combine(CacheDirectory, Segment.MessageId), FileMode.Create, FileAccess.Write, FileShare.None);
							DownloadingQueue.Add(Segment, Stream);

							if (Connection.Group != Segment.Groups[0])
							{
								Connection.SelectGroup(Segment.Groups[0]);

								while (Connection.Status == ConnectionStatus.SelectingGroup) { }
							}

							Connection.DownloadSegment(Segment, Stream);
						}
					}
				}
			} while (Running);
                     }
		}