using skyscraper5.Skyscraper.Scraper; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace skyscraper5.UI.StreamAcquisition { public abstract class StreamSource { protected abstract void StartSourceEx(); private bool started; private Thread thread; protected SkyscraperContext context; protected bool stopRequested; public virtual string GetSourceName() { return this.GetType().Name; } public StreamSourceState State { get; protected set; } public Thread StartSource(SkyscraperContext context) { if (started) throw new InvalidOperationException("already started"); this.context = context; this.thread = new Thread(StartSourceEx); this.thread.Priority = ThreadPriority.Lowest; this.thread.Name = String.Format("Skyscraper5.UI Source: {0}", GetSourceName()); started = true; this.thread.Start(); this.State = StreamSourceState.Running; return this.thread; } public void StopSource() { stopRequested = true; } } public enum StreamSourceState { Ready, Running, Crashed, Finished, StoppedByUser } }