Skip to content

Not sure this object correctly disposes itself? #114

@pjsgsy

Description

@pjsgsy

Just an observation based on a week or so of using this. It sometimes seems to still be running operations, after it gets disposed of, resulting in this error

System.NullReferenceException: Object reference not set to an instance of an object. Total t: 10:20:27.3523791 01:30:32
at ShellProgressBar.ProgressBar.DisplayProgress()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireNextTimers()

This is odd, because when I first came across it, and for performance reasons, I set the option which I believed was supposed to disable the timer

    var options = new ProgressBarOptions
    {
        ProgressCharacter = '─',
        ProgressBarOnBottom = true,
        DisplayTimeInRealTime = false
    };

Anyway - Simple structure

      `using (var pbar = new ProgressBar(totalTicks, "Training... (you may early terminate by pressing 'X')", options))
      {
      pbar.Tick($"epoch: {epoch} element: {i,6}, loss: {totalLoss / (double)i:0.00000
      
       System.Threading.Thread.Sleep(50); // small delay to prevent any issues with progress bar desposed before finishing update
      }

`

I found it necessary to add that .Sleep to prevent it happening almost all the time in fast loops. Increase the timer and the problem gets less, but this of course slows down your training loops. Pretty sure the issue is the timer is still running after the loop is finished with the pbar object, but maybe I am doing something really silly? ;)

I did take a quick look at the code. Here, not sure why a new timer is created and displayprogress not just run, but I'm sure it is needed for something.

		if (this.Options.DisplayTimeInRealTime)
			_timer = new Timer((s) => OnTimerTick(), null, 500, 500);
		else //draw once
			_timer = new Timer((s) =>
			{
				_timer.Dispose();
				DisplayProgress();
			}, null, 0, 1000);

Just reporting it as coming back to desk alffer leaving a long process running and it bailed with the error after about 6 hours of work :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions