dsuryd / dotNetify

Simple, lightweight, yet powerful way to build real-time web apps.
https://dotnetify.net
Other
1.17k stars 164 forks source link

MulticastVM issue #184

Closed crx-master closed 5 years ago

crx-master commented 5 years ago

Started recently to use dotNetify and had an issue with MulticastVM that is reproducible at the dashboard demo.

The demo uses BaseVM and generates different dashboard states for each client.

Just updated the demo app to 3.3.1 (server and client), and changed BaseVM to MulticastVM on Dashboard.cs.

Browse http://localhost:5000 at more than one instance and MulticastVM, as expected, generates same data for each client. The screens update beautifully synchronized on every client.

But then, just click on "Form" at any of the clients to stop all client updates. If you go back to the "Dashboard" will receive the updated data from the server, but just once.

Should I do something else to have this synchronized demo working correctly?

crx-master commented 5 years ago

MulticastVM Dispose() method is being called at every client disconnection.

The IDisposable.Dispose() method purpose should be to perform all objects cleanup to help the garbage collector, and be called just when the object is not needed anymore. But this is not the case at the reported demo issue.

I think MulticastVM should be disposed only if there is no more remaining alive connections.

dsuryd commented 5 years ago

I should've made it clearer in the documentation that if a multicast view model needs to dispose resources only after the last client disconnects, then it should override Dispose(bool disposing) instead. For the dashboard demo, the issue will be resolved if you replace the Dispose override with the following:

protected override void Dispose(bool disposing)
{
   if (disposing)
      _subscription?.Dispose();
}
crx-master commented 5 years ago

I consider this issue solved, but I would keep the suggestion for a future version: only dispose MulticastView after the last client disconnects. Feels like it would be the correct behavior.

Thanks for the great software @dsuryd