/// <summary> /// Works the specified data. /// </summary> /// <param name="data">The specified data.</param> private void Worker(object data) { NetworkTaskThreadArgs args = (NetworkTaskThreadArgs)data; while (!args.Stop) { this.Execute(args.NetworkTaskParameter); Thread.Sleep(args.PollDelay); } }
/// <summary> /// Initializes a new instance of the <see cref="NetworkTask"/> class. /// </summary> /// <param name="connection">The connection of the network task.</param> /// <param name="intervalTime">The interval time.</param> /// <exception cref="ArgumentNullException"> /// Is thrown if the specified value is null: /// connection - The value must not be null. /// </exception> public NetworkTask(IConnection connection, int intervalTime = 1000) { this.Connection = connection ?? throw new ArgumentNullException(nameof(connection), "The value must not be null."); this.networkTaskThread = new Thread(this.Worker); this.networkTaskThreadArgs = new NetworkTaskThreadArgs(intervalTime); }