/// <summary> /// Reads data from file /// </summary> private void LoadData(Object obj) { // Only one thread can read the data lock (locker) { if (this.state == LinesCounterState.Created) { this.state = LinesCounterState.Pending; try { this.reader = new LinesReader(this.hashCodeProvider); // Open stream Stream stream = new FileStream(this.fileName, FileMode.Open); // Request data from LinesReader this.data = this.reader.Read(stream); } finally { //If no data or instance is disposed set object state to Broken this.state = this.data == null || this.disposed ? LinesCounterState.Broken : LinesCounterState.Ready; this.reader = null; } } } //this.state = LinesCounterState.Ready; }
// // methods // ///<summary> /// Central method for cleaning up resources ///</summary> protected virtual void Dispose(Boolean disposing) { // Check to see if Dispose has already been called. if (!this.disposed) { // If disposing is true, then this method was called through the // public Dispose() if (disposing) { if (this.reader != null) { this.reader.Cancel(); } } // Always release or cleanup (any) unmanaged resources } this.disposed = true; this.state = LinesCounterState.Broken; }