Difference between Shutdown and Dispose

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
User avatar
baldo
Sr. Member
Sr. Member
Posts: 13
Joined: 19 Nov 2019, 12:15

Difference between Shutdown and Dispose

Post by baldo »

In the GettingStarted example I see that you have an overridden Shutdown() method and an overridden Dispose() method.
They do the same thing i.e. they dispose of the alarmTimer.
While debugging I see that when Stop() is called on the ServerManager, it calls the Shutdown() methods of all the node managers (just one in this case) that have been added to it. And then it calls the Dispose() method, but looks like the job has been already done.
So what I don't get is the purpose of the Shutdown() method. I think that the idea is that it should release everything the node manager is using and is the only one that takes care of it. So maybe instead of duplicating the code, isn't the Shutdown() method supposed to call the Dispose() method from within itself?. Apparently not, because Dispose() is called in a later stage, but than why does Shutdown() even exists?

Thanks,
baldo

User avatar
h2k_toy
Full Member
Full Member
Posts: 9
Joined: 24 Sep 2020, 09:13

Re: Difference between Shutdown and Dispose

Post by h2k_toy »

This is a very basic question for .NET programming.

The Dispose method is a implementation of microsoft's IDisposable method. It is intended to be implemented to cleanup self-managed resources in opposite to memory managed by the garbage collector. So it is a very basic method which applies to lot's of custom .NET classes and also classes provided by the microsoft .net framework.

The shutdown method is a method coming from UA-Server.

Basically, if a server has a shutdown method it is likely you can call startup after that once more. But it depends on the implementation if a server provides this. I dont know if the ua server can do this. Often objects are used only once but for my serverviewmodel this applies.

The basic difference is, that Dispose is a common impl of abstract method defined by microsoft. Once it is called the object is "dead" and there is a special exception "ObjectAllreadyDisposed" which you can throw if somebody uses a disposed method.

In opposite to that such shutdown methods are server specific, defined by UA library.

A server which is called "Dispose" in not shutdown state should shutdown on it's own and cleanup properly. At least this is how i implement it always. Shutdown of servers may also have background activity. Then i would name it "BeginShutdown" to clarify the process is not finished after the method returns.

Post Reply