We have developed a number of custom dll's which are called by third-party Windows applications. These dlls are loaded / unloaded as required.
我们开发了许多由第三方Windows应用程序调用的自定义dll。这些dll根据需要加载/卸载。
Most of the dlls call web services and these need to have urls, timeouts, etc configured.
大多数dll都调用Web服务,这些服务需要配置URL,超时等。
Because the dll is not permanently in memory, it has to read the configuration every time it is invoked. This seems sub-optimal to me.
因为dll不是永久存储在内存中,所以每次调用时都必须读取配置。这对我来说似乎不太理想。
Is there a better way to handle this?
有没有更好的方法来处理这个?
Note: The configurable information is in an xml file so that the IT department can alter as required. They would not accept registry edits.
注意:可配置信息位于xml文件中,以便IT部门可以根据需要进行更改。他们不接受注册表编辑。
Note: These dll's cater for a number of third-party applications, It esentially implements an external EDMS interface. The vendors would not accept passing the required parameters.
注意:这些dll适用于许多第三方应用程序,它实际上实现了一个外部EDMS接口。供应商不接受传递所需的参数。
Note: It’s a.NET application and the dll is written in C#. Essentially, there are both thick (Windows application) and thin clients that access this dll when they need to perform some kind of EDMS operation. The EDMS interface is defined as a set of calls that have to be implemented in the dll and the dll decides how to implement the EDMS functions e.g. for some clients, “Register Document” would update a DB and for others the same call would utilise a third-party EDMS system. There are no ASP clients.
注意:它是一个.NET应用程序,dll是用C#编写的。从本质上讲,有厚(Windows应用程序)和瘦客户端在需要执行某种EDMS操作时访问此dll。 EDMS接口被定义为必须在dll中实现的一组调用,并且dll决定如何实现EDMS功能,例如,对于某些客户,“注册文档”将更新数据库,而对于其他客户,相同的调用将使用第三方EDMS系统。没有ASP客户端。
My understanding is that the dll is loaded when the client wants to access an EDMS operation and is then unloaded when the call is finished. The client may not need to do another EDMS operation for a while (in some cases over an hour).
我的理解是当客户端想要访问EDMS操作时加载dll,然后在调用完成时卸载。客户端可能暂时不需要进行另一次EDMS操作(在某些情况下超过一小时)。
7 个解决方案
#1
1
Use the registry to store your configuration information, it's definitely fast enough.
使用注册表来存储您的配置信息,它肯定足够快。
#2
1
I think you need to provide more information. There are so many approaches at persisting configuration information. We don't even know the development platform. .Net?
我想你需要提供更多信息。持久化配置信息的方法很多。我们甚至不知道开发平台。 。净?
-
I wouldn't rely on the registry unless I was sure it would always be available. You might get away with that on client machines, but you've already mentioned webservices.
除非我确信它始终可用,否则我不会依赖注册表。您可能会在客户端计算机上使用它,但您已经提到过webservices。
-
XML file in the current directory seems to be very popular now for server side third-party dlls. But those configurations are optional.
对于服务器端第三方dll,当前目录中的XML文件似乎非常流行。但这些配置是可选的。
-
If this is ASP, Your Trust Level will be very important in choosing a configuration persistance method.
如果这是ASP,则您的信任级别在选择配置持久性方法时非常重要。
-
You may be able to use your Application server's "Application Scope". Which gets loaded once per lifetime of the application. Your DLL can invalidate that data if it detects it needs too.
您可以使用应用程序服务器的“应用程序范围”。每个应用程序的生命周期加载一次。如果检测到需要,您的DLL可以使该数据无效。
-
I've used text files, XML files, database, various IPC like shared memory segments, application scope, to persist configuration information. It depends a lot on the specifics of your project.
我使用了文本文件,XML文件,数据库,各种IPC,如共享内存段,应用程序范围,来保存配置信息。这在很大程度上取决于项目的具体情况。
Care to elaborate further?
需要进一步阐述吗?
EDIT. Considering your clarifications, I'd go with an XML file. This custom XML file would be loaded using a search path that has been predefined and documented. If this is ASP.Net you can use Server.MapPath() for example to check various folders like App_Data. The DLL would check the current directory for the configuration file first though. You can then use a "manager" thread that holds the configuration data and passes it to any child threads that require it. The sharing can use IPC like a shared memory segment.
编辑。考虑到你的澄清,我会使用XML文件。将使用已预定义并记录的搜索路径加载此自定义XML文件。如果这是ASP.Net,您可以使用Server.MapPath()来检查各种文件夹,如App_Data。 DLL会首先检查当前目录中的配置文件。然后,您可以使用“管理器”线程来保存配置数据并将其传递给任何需要它的子线程。共享可以像共享内存段一样使用IPC。
This seems like hassle, but you have to store the information in some scope... Either from disk, memory ( application scope, session scope, DLL global scope, another process/IPC etc. )
这似乎很麻烦,但你必须将信息存储在某个范围内......来自磁盘,内存(应用程序范围,会话范围,DLL全局范围,另一个进程/ IPC等)
ASP.Net also gives you the ability to add custom configuration sections to standard configuration files like web.config. You can access those sections at will and they will not depend on when your DLL was loaded.
ASP.Net还使您能够将自定义配置节添加到标准配置文件,如web.config。您可以随意访问这些部分,它们不依赖于DLL的加载时间。
Why do you believe your DLL is being removed from memory?
为什么你认为你的DLL被从内存中删除?
#3
0
Why don't you let the calling application fill out a data-structure with the stuff you need? Can be done as part of an init-call or so.
为什么不让调用应用程序用你需要的东西填充数据结构?可以作为初始化调用的一部分来完成。
#4
0
How often is the dll getting unloaded? COM dlls can control when they are unloaded via the DllCanUnload method. If these are COM components you could look at implementing some kind of timeout here to prevent frequent loads and unloads. Unless the dll is reload the configuration at a significant frequency it is unlikely to be a real performance bottleneck.
dll多久卸载一次? COM dll可以控制何时通过DllCanUnload方法卸载它们。如果这些是COM组件,您可以在此处查看实现某种超时以防止频繁加载和卸载。除非dll以很高的频率重新加载配置,否则它不太可能成为真正的性能瓶颈。
Knowing that the dll will reload its configuration at certain points is a useful feature, since it prevents the users wondering if they have to restart the host process, reboot the machine, etc for the configuration to take effect. You could even watch the file for changes to keep it up to date.
知道dll将在某些点重新加载其配置是一个有用的功能,因为它可以防止用户想知道他们是否必须重新启动主机进程,重启机器等以使配置生效。您甚至可以查看文件以进行更改以使其保持最新。
#5
0
I think the best way for a DLL to get configuration information is via the application that is using it - either via implicit "Init"-calls, like Nils suggested, or via their configuration files.
我认为DLL获取配置信息的最佳方式是通过使用它的应用程序 - 通过隐式“Init”调用,如Nils建议,或通过其配置文件。
DLLs shouldn't usually "configure themselves", as they can never be sure in which context they are used. Different users (as in applications) may have different configuration settings to make.
DLL通常不应“自行配置”,因为它们永远无法确定它们在哪种上下文中使用。不同的用户(如在应用程序中)可能具有不同的配置设置。
Since you said that the application is written in .NET, you should probably simply require them to put the necessary configuration for your DLL's functions in their configuration file ("whatever.exe.config") and access it from your DLL via AppSettings or even better via a custom configuration section.
既然你说应用程序是用.NET编写的,你可能只需要它们在你的配置文件(“whatever.exe.config”)中为你的DLL函数提供必要的配置,并通过AppSettings从你的DLL访问它甚至通过自定义配置部分更好。
Additionally, you may want to provide sensible default values for settings where that is possible (probably not for network addresses though).
此外,您可能希望为可能的设置提供合理的默认值(尽管可能不适用于网络地址)。
#6
0
If the dlls are loaded and unloaded from memory only at a gap of every 1 hour or so the in-efficiency due to mslal initializations (read file / registry) will be negligible.
如果dll仅在每1小时左右的间隙从内存中加载和卸载,则由于mslal初始化(读取文件/注册表)而导致的效率可忽略不计。
However if this is more frequent, a higher inefficiency would be the physical action of loading and unloading of dlls. This could be more of an in-efficiency than small initializations.
但是,如果这种情况更频繁,那么更高效率就是装载和卸载dll的物理行为。这可能更多的是效率低于小的初始化。
It might therefore be better to keep them pinned in memory. That way the initialization performed at the load time, does not get repeated and you also avoid the in-efficiency of load and unload. You solve 2 issues this way.
因此,最好将它们固定在内存中。这样,在加载时执行的初始化不会重复,您还可以避免加载和卸载的效率。你用这种方式解决了2个问题。
I could tell you how to do this in C++. Not sure how you would do this in C#. GetModuleHandle + making an extra a LoadLibrary call on this handle is how i would do this in C++.
我可以告诉你如何用C ++做到这一点。不确定如何在C#中执行此操作。 GetModuleHandle +在这个句柄上进行额外的LoadLibrary调用是我在C ++中如何做到的。
#7
0
One way to do it is to have an Interface in the DLL which specify the required settings.
一种方法是在DLL中使用一个指定所需设置的接口。
Then it's up to the "application project" to have a class that implements this interface and pass it to the DLL at initiation, this makes you free to change the implementation depending on project. One might read from web.config while another reads from DB.
然后由“应用程序项目”来创建一个实现此接口的类并在启动时将其传递给DLL,这使您可以根据项目*更改实现。有人可能从web.config读取而另一个从DB读取。
#1
1
Use the registry to store your configuration information, it's definitely fast enough.
使用注册表来存储您的配置信息,它肯定足够快。
#2
1
I think you need to provide more information. There are so many approaches at persisting configuration information. We don't even know the development platform. .Net?
我想你需要提供更多信息。持久化配置信息的方法很多。我们甚至不知道开发平台。 。净?
-
I wouldn't rely on the registry unless I was sure it would always be available. You might get away with that on client machines, but you've already mentioned webservices.
除非我确信它始终可用,否则我不会依赖注册表。您可能会在客户端计算机上使用它,但您已经提到过webservices。
-
XML file in the current directory seems to be very popular now for server side third-party dlls. But those configurations are optional.
对于服务器端第三方dll,当前目录中的XML文件似乎非常流行。但这些配置是可选的。
-
If this is ASP, Your Trust Level will be very important in choosing a configuration persistance method.
如果这是ASP,则您的信任级别在选择配置持久性方法时非常重要。
-
You may be able to use your Application server's "Application Scope". Which gets loaded once per lifetime of the application. Your DLL can invalidate that data if it detects it needs too.
您可以使用应用程序服务器的“应用程序范围”。每个应用程序的生命周期加载一次。如果检测到需要,您的DLL可以使该数据无效。
-
I've used text files, XML files, database, various IPC like shared memory segments, application scope, to persist configuration information. It depends a lot on the specifics of your project.
我使用了文本文件,XML文件,数据库,各种IPC,如共享内存段,应用程序范围,来保存配置信息。这在很大程度上取决于项目的具体情况。
Care to elaborate further?
需要进一步阐述吗?
EDIT. Considering your clarifications, I'd go with an XML file. This custom XML file would be loaded using a search path that has been predefined and documented. If this is ASP.Net you can use Server.MapPath() for example to check various folders like App_Data. The DLL would check the current directory for the configuration file first though. You can then use a "manager" thread that holds the configuration data and passes it to any child threads that require it. The sharing can use IPC like a shared memory segment.
编辑。考虑到你的澄清,我会使用XML文件。将使用已预定义并记录的搜索路径加载此自定义XML文件。如果这是ASP.Net,您可以使用Server.MapPath()来检查各种文件夹,如App_Data。 DLL会首先检查当前目录中的配置文件。然后,您可以使用“管理器”线程来保存配置数据并将其传递给任何需要它的子线程。共享可以像共享内存段一样使用IPC。
This seems like hassle, but you have to store the information in some scope... Either from disk, memory ( application scope, session scope, DLL global scope, another process/IPC etc. )
这似乎很麻烦,但你必须将信息存储在某个范围内......来自磁盘,内存(应用程序范围,会话范围,DLL全局范围,另一个进程/ IPC等)
ASP.Net also gives you the ability to add custom configuration sections to standard configuration files like web.config. You can access those sections at will and they will not depend on when your DLL was loaded.
ASP.Net还使您能够将自定义配置节添加到标准配置文件,如web.config。您可以随意访问这些部分,它们不依赖于DLL的加载时间。
Why do you believe your DLL is being removed from memory?
为什么你认为你的DLL被从内存中删除?
#3
0
Why don't you let the calling application fill out a data-structure with the stuff you need? Can be done as part of an init-call or so.
为什么不让调用应用程序用你需要的东西填充数据结构?可以作为初始化调用的一部分来完成。
#4
0
How often is the dll getting unloaded? COM dlls can control when they are unloaded via the DllCanUnload method. If these are COM components you could look at implementing some kind of timeout here to prevent frequent loads and unloads. Unless the dll is reload the configuration at a significant frequency it is unlikely to be a real performance bottleneck.
dll多久卸载一次? COM dll可以控制何时通过DllCanUnload方法卸载它们。如果这些是COM组件,您可以在此处查看实现某种超时以防止频繁加载和卸载。除非dll以很高的频率重新加载配置,否则它不太可能成为真正的性能瓶颈。
Knowing that the dll will reload its configuration at certain points is a useful feature, since it prevents the users wondering if they have to restart the host process, reboot the machine, etc for the configuration to take effect. You could even watch the file for changes to keep it up to date.
知道dll将在某些点重新加载其配置是一个有用的功能,因为它可以防止用户想知道他们是否必须重新启动主机进程,重启机器等以使配置生效。您甚至可以查看文件以进行更改以使其保持最新。
#5
0
I think the best way for a DLL to get configuration information is via the application that is using it - either via implicit "Init"-calls, like Nils suggested, or via their configuration files.
我认为DLL获取配置信息的最佳方式是通过使用它的应用程序 - 通过隐式“Init”调用,如Nils建议,或通过其配置文件。
DLLs shouldn't usually "configure themselves", as they can never be sure in which context they are used. Different users (as in applications) may have different configuration settings to make.
DLL通常不应“自行配置”,因为它们永远无法确定它们在哪种上下文中使用。不同的用户(如在应用程序中)可能具有不同的配置设置。
Since you said that the application is written in .NET, you should probably simply require them to put the necessary configuration for your DLL's functions in their configuration file ("whatever.exe.config") and access it from your DLL via AppSettings or even better via a custom configuration section.
既然你说应用程序是用.NET编写的,你可能只需要它们在你的配置文件(“whatever.exe.config”)中为你的DLL函数提供必要的配置,并通过AppSettings从你的DLL访问它甚至通过自定义配置部分更好。
Additionally, you may want to provide sensible default values for settings where that is possible (probably not for network addresses though).
此外,您可能希望为可能的设置提供合理的默认值(尽管可能不适用于网络地址)。
#6
0
If the dlls are loaded and unloaded from memory only at a gap of every 1 hour or so the in-efficiency due to mslal initializations (read file / registry) will be negligible.
如果dll仅在每1小时左右的间隙从内存中加载和卸载,则由于mslal初始化(读取文件/注册表)而导致的效率可忽略不计。
However if this is more frequent, a higher inefficiency would be the physical action of loading and unloading of dlls. This could be more of an in-efficiency than small initializations.
但是,如果这种情况更频繁,那么更高效率就是装载和卸载dll的物理行为。这可能更多的是效率低于小的初始化。
It might therefore be better to keep them pinned in memory. That way the initialization performed at the load time, does not get repeated and you also avoid the in-efficiency of load and unload. You solve 2 issues this way.
因此,最好将它们固定在内存中。这样,在加载时执行的初始化不会重复,您还可以避免加载和卸载的效率。你用这种方式解决了2个问题。
I could tell you how to do this in C++. Not sure how you would do this in C#. GetModuleHandle + making an extra a LoadLibrary call on this handle is how i would do this in C++.
我可以告诉你如何用C ++做到这一点。不确定如何在C#中执行此操作。 GetModuleHandle +在这个句柄上进行额外的LoadLibrary调用是我在C ++中如何做到的。
#7
0
One way to do it is to have an Interface in the DLL which specify the required settings.
一种方法是在DLL中使用一个指定所需设置的接口。
Then it's up to the "application project" to have a class that implements this interface and pass it to the DLL at initiation, this makes you free to change the implementation depending on project. One might read from web.config while another reads from DB.
然后由“应用程序项目”来创建一个实现此接口的类并在启动时将其传递给DLL,这使您可以根据项目*更改实现。有人可能从web.config读取而另一个从DB读取。