Can you create an initialize method for DLL?

纵饮孤独 提交于 2020-01-17 07:46:11

问题


I need to create a service, but the service needs to be in a already existing Class Library file and also the new service needs to start running after the Class Library is installed. Is there a way to create an Init() method or other way to start service inside in Class Library? The project supports max .NET 3.5

Sorry if it sounds dumb, i'm new to the Class Library stuff


回答1:


No, class libraries don't support initialization like this.

Note that the library wouldn't even be loaded until it's first used anyway. You could write a type initializer for some appropriate type, and make that start the service - but personally I'd make it explicit if at all possible. (Doing lots of work in type initializers can lead to difficult-to-diagnose issues.)



来源:https://stackoverflow.com/questions/44965314/can-you-create-an-initialize-method-for-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!