Lifetime of the Aspose License classes

Hello,

I am confused about the life time of the Aspose License class. If I set my license as follows…

Aspose.Words.License license = new Aspose.Words.License();
license.SetLicense(“Aspose.Total.lic”);

… Does the lifetime of the license in my process last the life time of the License class? If it is in a references static singleton class it will be available for the lifttime of my process. If it is in a method then it is available for the live time of the method and I will have to reinitialise it in other places.

Can you please confirm/clarify the behaviour?

Kind regards,
JP O’Gorman

Your code is correct.

The License class is merely a "wrapper" that initializes some static structures inside the component to indicate the component is licensed. So when the license object you created is garbage collected the component will continue to work in the licensed mode.

I think this way of creating a license object and calling a method on it was selected to maintain "callability" from COM clients. Static methods or ctors with parameters are not supported in COM Interop therefore a normal ctor and normal object are used.

Hi,

Thank you for that. Just one further question.

Currently I have no one central place within my process to initialise the aspose licence(s). This means I have duplicate code to initialise the license for a particular aspose component. Can you tell me if there is there as much of a performace hit on the second SetLicense() call as there is on the first one? This will help me to prioritise the refactoring of my code.

Thanks,
JP

Processing for any SetLicense call takes the same amount of time. If you call it several times there is no harm and nobody will notice. It is not wise probably to call it too often, say before every document is processed. Again, it will not be noticeable, but just a waste you know of.

You can put your license init code into a static constructor of some .NET class that will be used when you use an Aspose component.

I had the same kind of question about how often and where to call the licensing code. Would putting the licensing code in the Application_Start method in Global.asax be a good solution? Have the developers at Aspose tried something like that and if they have what were the results?