Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StopableThread"/> class.
 /// </summary>
 /// <param name="init"> The function to call when initialzing the run loop (can be <see langword="null"/>). </param>
 /// <param name="term"> The function to call when terminating the run loop (can be <see langword="null"/>). </param>
 /// <param name="tick"> The function that handles the thread tick, cannot be <see langword="null"/>. </param>
 /// <param name="name"> The name of the thread. </param>
 public StopableThread(ThreadStart init, ThreadStart term, ThreadStart tick, string name = null)
 {
     LoggedException.RaiseIf(tick == null, nameof(StopableThread), "Unable to create thread!", new ArgumentNullException("tick", "tick cannot be null!"));
     TickCooldown = 10;
     this.init    = init;
     this.term    = term;
     this.tick    = tick;
     Name         = name;
     nameSet      = !string.IsNullOrEmpty(name);
     thread       = ThreadBuilder.CreateSTA(Run, name);
 }
Пример #2
0
        /// <summary>
        /// Starts the thread.
        /// </summary>
        public void Start()
        {
            if (running)
            {
                Log.Warning(nameof(StopableThread), "Attempted to start already running thread, call ignored.");
                return;
            }
            else if (thread == null || thread.ThreadState != System.Threading.ThreadState.Unstarted)
            {
                thread = ThreadBuilder.CreateSTA(Run, Name);
            }

            thread.Start();
        }