473,804 Members | 3,225 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

COM Interop -- Class Library vs. EXE

Hello,

I am developing classes in C# that are called from PHP via COM. The C# code
does a lot of work to establish internal data structures, and I would like
these data structures to persist so that I do not have to recreate them each
time the COM code is called.

For example, imagine a function MyObject.BuildI nternalDataStru ctures() which
takes a long time. Another function, MyObject.UseInt ernalDataStruct ures(),
is called repeatedly. The first time UseInternalData Structures is called,
it detects that the structures haven't been built, so it calls
BuildInternalDa taStructures. Subsequent calls to UseInternalData Structures
do not need to incur the penaly of building the internal data structures.

The problem is that on my web server, PHP instantiates a new instance of my
object each time a PHP page is hit -- and destroys the object (and unloads
my DLL) when the page completes executing. So the next time the user hits a
PHP page that calls out to MyObject.UseInt ernalDataStruct ures(), it has to
rebuild everything again from scratch.

Is there a way to build a COM server as an EXE, so that it can run in the
background, maintaining its state, while allowing COM consumers (such as
PHP) to call into it?

Thanks

Greg
Dec 27 '05 #1
3 3464
Hi,

The problem is that on my web server, PHP instantiates a new instance of
my
object each time a PHP page is hit -- and destroys the object (and unloads
my DLL) when the page completes executing. So the next time the user hits
a
PHP page that calls out to MyObject.UseInt ernalDataStruct ures(), it has to
rebuild everything again from scratch.
Does it unload the dll? That seems like very inefficienty ! , imagine 100
requests each loading/unloading the same dll
Is there a way to build a COM server as an EXE, so that it can run in the
background, maintaining its state, while allowing COM consumers (such as
PHP) to call into it?


First of all I would check in the unloading matter, it should be
configurable somehow.

If not possible then what you could do is using another process to hold the
internal structures, then the dll can communicate with it using remoting for
example. In anyway it would be less efficient.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Dec 27 '05 #2

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:OH******** *****@TK2MSFTNG P15.phx.gbl...
Hi,

The problem is that on my web server, PHP instantiates a new instance of
my
object each time a PHP page is hit -- and destroys the object (and
unloads
my DLL) when the page completes executing. So the next time the user
hits a
PHP page that calls out to MyObject.UseInt ernalDataStruct ures(), it has
to
rebuild everything again from scratch.


Does it unload the dll? That seems like very inefficienty ! , imagine 100
requests each loading/unloading the same dll


I agree. It is much more likely that your objects are destroyed, but your
DLL is not unloaded. This is how ASP.OLD worked. If this is the case you
have static scope to store data between calls. Just be sure to make access
to static resources thread-safe.

David
Dec 27 '05 #3
Gregory,

I think it is a simple matter of moving your data structures to a static
variable. Once the CLR is loaded, it is not going to be unloaded for the
life of the process (or at least, it shouldn't). Just make it static.

And if you find that the CLR is being unloaded, then I would create a
class derived from ServicedCompone nt which uses object pooling. You can
then create a pool of your objects, and incur the cost of initializing your
data structures on construction of your object.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Gregory Hassett" <gh******@hotma il.com> wrote in message
news:eQ******** ******@TK2MSFTN GP09.phx.gbl...
Hello,

I am developing classes in C# that are called from PHP via COM. The C#
code
does a lot of work to establish internal data structures, and I would like
these data structures to persist so that I do not have to recreate them
each
time the COM code is called.

For example, imagine a function MyObject.BuildI nternalDataStru ctures()
which
takes a long time. Another function,
MyObject.UseInt ernalDataStruct ures(),
is called repeatedly. The first time UseInternalData Structures is called,
it detects that the structures haven't been built, so it calls
BuildInternalDa taStructures. Subsequent calls to
UseInternalData Structures
do not need to incur the penaly of building the internal data structures.

The problem is that on my web server, PHP instantiates a new instance of
my
object each time a PHP page is hit -- and destroys the object (and unloads
my DLL) when the page completes executing. So the next time the user hits
a
PHP page that calls out to MyObject.UseInt ernalDataStruct ures(), it has to
rebuild everything again from scratch.

Is there a way to build a COM server as an EXE, so that it can run in the
background, maintaining its state, while allowing COM consumers (such as
PHP) to call into it?

Thanks

Greg

Dec 27 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
14794
by: Patrick | last post by:
I am almost certain that I could use HTTP Post/Get to submit XML Web Service call (over SSL as well, if using Version 3 of MSXML2) from an ASP Application? However, would I only be able to call web-service in a an asynchronous mode (with a callback function)? If so, how?
0
3009
by: Shashank Date | last post by:
/* C# Gurus, I am trying to use interop marshalling to call SetCommTimeouts win32 API. But I keep getting the "Object reference not set to an instance of an object" error. Can anybody help me figure out why ? TIA.
1
8653
by: Craig | last post by:
I am having problems getting an ActiveX DLL written in VB6 to call a method in a C# class library component. My C# DLL is called CSharpProject.dll and contains a public class called CSharpClass. In this class is a single public method that returns the string "Hello from C sharp". My VB6 ActiveX DLL references the C# DLL (CSharpProject.dll) using the
7
4702
by: Josef | last post by:
Hello, I want to create a C# class library which I can use in an Excel VBA macro. I created a C# class library and set the "Register for COM Interop" option in Visual Studio to TRUE. Now in Excel I can use this library but the intellisense does not show any properties or functions of the class. Do I have to add any keywords or GUID to each public function and property in C#? Do I have to load the library to the global assembly cache?...
20
3200
by: Razzie | last post by:
Hey all, I'm really going through a small hell right now - I've completely lost it :) I made a project, using two interop libraries from exchange (created them as in this msdn article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsmtps/html/writingmngsinks.asp). I set my project properties as 'Register as COM interop' to true, I can install it my project on my developement machine without a flaw. Great.
1
2127
by: Hatim Ali | last post by:
Hello, I have a class library project which has a class supporting COM+ transactions. This class library project refers a COM interop assembly. Now i need to register the assembly after compiling this class library projects into GAC. Registrering it into GAC requires tthat the assembly should have a strong name. Now when i use attribute and compile the class library project it prompts me that the interop assembly should have a strong...
8
3426
by: Rob Edwards | last post by:
When trying to add the Microsoft CDO for Exchange Management Library (aka CDOEXM.dll) I receive the following message: "A reference to 'Microsoft CDO for Exchange Management Library' could not be added. Converting the type library to a .Net assembly failed. A depended type library 'CDO' could not be converted to a .NET assembly. A dependent type library 'ADODB' could not be converted to a .NET assembly. Item has already been added." ...
2
1009
by: JimM | last post by:
what do I need to use in vb.net to create an object as I do in vb6: Dim o as Object Set o = CreateObject("Class1.Test") Thanks
4
2350
by: Greg | last post by:
I have a very simple Visual Basic .NET 2003 class library project ClassLibrary1 configured to run an external program (in this case C:\WINDOWS\system32\wscript.exe), in the Debugging Configuration Properties Dialog Box with command line arguments C:\test.vbs. When I run the project, I get an "unable to start debugging" error "unable to start program 'C:\WINDOWS\system32\wscript.exe'". Why do I get this error and how can I solve it? ...
1
2078
by: ropo | last post by:
I am using .NET 2.0 I have a C#.Net App, which uses a .NET Class Library, which accesses a COM object through interop. The C#.Net App also uses a mixed mode C++.Net Class library which uses an unmanaged win32 DLL, which uses another unmanaged win32 DLL which accesses the same COM object The COM object is in another process.
0
9708
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9588
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10327
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.