Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObjectDisposedException while calling Stop() #50

Open
fknx opened this issue Nov 15, 2017 · 3 comments
Open

ObjectDisposedException while calling Stop() #50

fknx opened this issue Nov 15, 2017 · 3 comments

Comments

@fknx
Copy link

fknx commented Nov 15, 2017

Hi,

I'm using the following code to react to the NotificationProcessStopped event:

// Listener contains the SqlDependencyEx instance
Listener.NotificationProcessStopped += (sender, args) =>
{
   Task.Run(async () =>
   {
      await Task.Delay(5000);
      AttemptReconnect();
   });
};

private void AttemptReconnect()
{
   try
   {
      Listener.Stop();
      Listener.Start();
   }
   catch
   {
      Task.Run(async () =>
      {
         await Task.Delay(5000);
         AttemptReconnect();
      });
   }
}

If I run this code and stop the SQL Server to simulate a disconnect, I am receiving an ObjectDisposedException: The CancellationTokenSource has been disposed in the Stop() method when the _threadSource.Token.IsCancellationRequested property is read in line 567 on the second reconnect attempt (and every reconnect attempt thereafter).

When I change this to _threadSource.IsCancellationRequested everything works fine.

@Siliconrob
Copy link
Contributor

So first time the token stops, then second time there is no token because it was disposed and now you want to use the token source to check if cancellation is requested?

From this
if ((_threadSource == null) || (_threadSource.Token.IsCancellationRequested))
to this
if ((_threadSource == null) || (_threadSource.IsCancellationRequested))

@fknx
Copy link
Author

fknx commented Nov 15, 2017

Yes that was the idea, since accessing the _threadSource.Token immediately causes the ObjectDisposedException.

@Siliconrob
Copy link
Contributor

I would suggest you submit a pull request with this change, and tag @dyatchenko . They are the only one that can make edits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants