473,406 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to share a static variable between 2 different process

Hi everybody,
I have a c# dll and I want to call the class library from several
applications.
I need some variables to be static in the memory space, not locally to each
process.
Thus, if application A modifies the variable X of a class contained in the
dll, application B should be able to see the changed value.
Does anybody has any idea of how to obtain this?

Thanks in advance.
Riccardo
Jul 8 '08 #1
6 9463
This is not possible with normall coding in .NET. You would need to setup
interprocess communication in a client server type way.
Remoting or WCF would be the best mechanisms for establishing but you would
need to work out which process should hold the master copy and then create a
service in it for the other processes to access it. You could potentially
propogate changes around with events/callbacks over the communication channel.

The other option is to hold the values in a database, or the registry or
some other centralised storage mechanism.
If you give a bit more information on the requirement we might be able to
help you choose the best way to do it.

HTH

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Riccardo" wrote:
Hi everybody,
I have a c# dll and I want to call the class library from several
applications.
I need some variables to be static in the memory space, not locally to each
process.
Thus, if application A modifies the variable X of a class contained in the
dll, application B should be able to see the changed value.
Does anybody has any idea of how to obtain this?

Thanks in advance.
Riccardo
Jul 8 '08 #2
This is not a good news for me :-)
I'll try to explain better: my dll has been exposed as a COM object thanks
to interop. All the clients could call some methods like ListAvailableSeats,
ReserveSeat, PaySeat, etc. The dll has a full control on the access db where
available seats are stored. The db just has 2 fields: Id, Description. I
cannot change its structure.
The multiple COM clients could be located on different machines, require the
list of the available seats, reserve one of them and pay the reserved one. Of
course one client could pay only seats who reserved itself.
The only operation that the dll could do on the db (except reading it) is to
remove the appropriate record whenever the seat is paid.
What I would like to do is keeping trace (possibly only in memory, not on
disk) of the reservations and the related process who made the reservations.

Thanks.
Riccardo Mingozzi

"Ciaran O''Donnell" wrote:
This is not possible with normall coding in .NET. You would need to setup
interprocess communication in a client server type way.
Remoting or WCF would be the best mechanisms for establishing but you would
need to work out which process should hold the master copy and then create a
service in it for the other processes to access it. You could potentially
propogate changes around with events/callbacks over the communication channel.

The other option is to hold the values in a database, or the registry or
some other centralised storage mechanism.
If you give a bit more information on the requirement we might be able to
help you choose the best way to do it.

HTH

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Riccardo" wrote:
Hi everybody,
I have a c# dll and I want to call the class library from several
applications.
I need some variables to be static in the memory space, not locally to each
process.
Thus, if application A modifies the variable X of a class contained in the
dll, application B should be able to see the changed value.
Does anybody has any idea of how to obtain this?

Thanks in advance.
Riccardo
Jul 8 '08 #3
"Riccardo" <Ri******@discussions.microsoft.comwrote in message
news:D4**********************************@microsof t.com...
This is not a good news for me :-)
I'll try to explain better: my dll has been exposed as a COM object thanks
to interop. All the clients could call some methods like
ListAvailableSeats,
ReserveSeat, PaySeat, etc. The dll has a full control on the access db
where
available seats are stored. The db just has 2 fields: Id, Description. I
cannot change its structure.
The multiple COM clients could be located on different machines, require
the
list of the available seats, reserve one of them and pay the reserved one.
Of
course one client could pay only seats who reserved itself.
The only operation that the dll could do on the db (except reading it) is
to
remove the appropriate record whenever the seat is paid.
What I would like to do is keeping trace (possibly only in memory, not on
disk) of the reservations and the related process who made the
reservations.
Go beyond COM: use COM+.
Make the class inside your DLL inherit from
System.EnterpriseServices.ServicedComponent. Then register the DLL in
ComponentServices in a server. If you need to call it from various client
PCs, you can generate a proxy from the Component Services administration
tool, and then install the proxy on the clients. This is not needed if the
programs that call the dll are running on the same computer.
You can configure COM+ to run the DLL in server mode (versus library
mode). You can then use static variables, or use the Shared Property Manager
in COM+, to share your values in memory between all callers.

The complete process is a little more complex than hinted above.
Microsoft official course number 2557 describes how to program COM+ using
..Net.

Jul 8 '08 #4
Ok, so thats a little different. If you are using COM then you can load the
dll into Component Services in Windows as a COM+ server. There are various
tutorials on the web that will talk you through registering the server and
generating a type library (tlb) file to add as a reference to your client
code.
Architecturally it would be nicer to move away from COM and setup a WCF
service to host the server and have that access a SQL Server (SQLEXPRESS is
free) database but if you really cant change that then dont worry about it.

Here is a page which gives a walkthrough of building a COM+ server
application which is implemented in .NET

Hope this helps

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Riccardo" wrote:
This is not a good news for me :-)
I'll try to explain better: my dll has been exposed as a COM object thanks
to interop. All the clients could call some methods like ListAvailableSeats,
ReserveSeat, PaySeat, etc. The dll has a full control on the access db where
available seats are stored. The db just has 2 fields: Id, Description. I
cannot change its structure.
The multiple COM clients could be located on different machines, require the
list of the available seats, reserve one of them and pay the reserved one. Of
course one client could pay only seats who reserved itself.
The only operation that the dll could do on the db (except reading it) is to
remove the appropriate record whenever the seat is paid.
What I would like to do is keeping trace (possibly only in memory, not on
disk) of the reservations and the related process who made the reservations.

Thanks.
Riccardo Mingozzi

"Ciaran O''Donnell" wrote:
This is not possible with normall coding in .NET. You would need to setup
interprocess communication in a client server type way.
Remoting or WCF would be the best mechanisms for establishing but you would
need to work out which process should hold the master copy and then create a
service in it for the other processes to access it. You could potentially
propogate changes around with events/callbacks over the communication channel.

The other option is to hold the values in a database, or the registry or
some other centralised storage mechanism.
If you give a bit more information on the requirement we might be able to
help you choose the best way to do it.

HTH

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Riccardo" wrote:
Hi everybody,
I have a c# dll and I want to call the class library from several
applications.
I need some variables to be static in the memory space, not locally to each
process.
Thus, if application A modifies the variable X of a class contained in the
dll, application B should be able to see the changed value.
Does anybody has any idea of how to obtain this?
>
Thanks in advance.
Riccardo
Jul 8 '08 #5
Sorry, maybe you forgot the link to the page.
Thanks.

"Ciaran O''Donnell" wrote:
Ok, so thats a little different. If you are using COM then you can load the
dll into Component Services in Windows as a COM+ server. There are various
tutorials on the web that will talk you through registering the server and
generating a type library (tlb) file to add as a reference to your client
code.
Architecturally it would be nicer to move away from COM and setup a WCF
service to host the server and have that access a SQL Server (SQLEXPRESS is
free) database but if you really cant change that then dont worry about it.

Here is a page which gives a walkthrough of building a COM+ server
application which is implemented in .NET

Hope this helps

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Riccardo" wrote:
This is not a good news for me :-)
I'll try to explain better: my dll has been exposed as a COM object thanks
to interop. All the clients could call some methods like ListAvailableSeats,
ReserveSeat, PaySeat, etc. The dll has a full control on the access db where
available seats are stored. The db just has 2 fields: Id, Description. I
cannot change its structure.
The multiple COM clients could be located on different machines, require the
list of the available seats, reserve one of them and pay the reserved one. Of
course one client could pay only seats who reserved itself.
The only operation that the dll could do on the db (except reading it) is to
remove the appropriate record whenever the seat is paid.
What I would like to do is keeping trace (possibly only in memory, not on
disk) of the reservations and the related process who made the reservations.

Thanks.
Riccardo Mingozzi

"Ciaran O''Donnell" wrote:
This is not possible with normall coding in .NET. You would need to setup
interprocess communication in a client server type way.
Remoting or WCF would be the best mechanisms for establishing but you would
need to work out which process should hold the master copy and then create a
service in it for the other processes to access it. You could potentially
propogate changes around with events/callbacks over the communication channel.
>
The other option is to hold the values in a database, or the registry or
some other centralised storage mechanism.
If you give a bit more information on the requirement we might be able to
help you choose the best way to do it.
>
HTH
>
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
>
>
"Riccardo" wrote:
>
Hi everybody,
I have a c# dll and I want to call the class library from several
applications.
I need some variables to be static in the memory space, not locally to each
process.
Thus, if application A modifies the variable X of a class contained in the
dll, application B should be able to see the changed value.
Does anybody has any idea of how to obtain this?

Thanks in advance.
Riccardo
Jul 8 '08 #6
Yes, it appears I did. Sorry about that.
Here it is:
http://my.execpc.com/~gopalan/dotnet...ntmanager.html

It might not be exactly what your after but it look like a good starter for 10
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Riccardo" wrote:
Sorry, maybe you forgot the link to the page.
Thanks.

"Ciaran O''Donnell" wrote:
Ok, so thats a little different. If you are using COM then you can load the
dll into Component Services in Windows as a COM+ server. There are various
tutorials on the web that will talk you through registering the server and
generating a type library (tlb) file to add as a reference to your client
code.
Architecturally it would be nicer to move away from COM and setup a WCF
service to host the server and have that access a SQL Server (SQLEXPRESS is
free) database but if you really cant change that then dont worry about it.

Here is a page which gives a walkthrough of building a COM+ server
application which is implemented in .NET

Hope this helps

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Riccardo" wrote:
This is not a good news for me :-)
I'll try to explain better: my dll has been exposed as a COM object thanks
to interop. All the clients could call some methods like ListAvailableSeats,
ReserveSeat, PaySeat, etc. The dll has a full control on the access db where
available seats are stored. The db just has 2 fields: Id, Description. I
cannot change its structure.
The multiple COM clients could be located on different machines, require the
list of the available seats, reserve one of them and pay the reserved one. Of
course one client could pay only seats who reserved itself.
The only operation that the dll could do on the db (except reading it) is to
remove the appropriate record whenever the seat is paid.
What I would like to do is keeping trace (possibly only in memory, not on
disk) of the reservations and the related process who made the reservations.
>
Thanks.
Riccardo Mingozzi
>
"Ciaran O''Donnell" wrote:
>
This is not possible with normall coding in .NET. You would need to setup
interprocess communication in a client server type way.
Remoting or WCF would be the best mechanisms for establishing but you would
need to work out which process should hold the master copy and then create a
service in it for the other processes to access it. You could potentially
propogate changes around with events/callbacks over the communication channel.

The other option is to hold the values in a database, or the registry or
some other centralised storage mechanism.
If you give a bit more information on the requirement we might be able to
help you choose the best way to do it.

HTH

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com


"Riccardo" wrote:

Hi everybody,
I have a c# dll and I want to call the class library from several
applications.
I need some variables to be static in the memory space, not locally to each
process.
Thus, if application A modifies the variable X of a class contained in the
dll, application B should be able to see the changed value.
Does anybody has any idea of how to obtain this?
>
Thanks in advance.
Riccardo
Jul 8 '08 #7

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

Similar topics

4
by: santosh | last post by:
Hello, I have a doubt about static variable. class B { private: static int x; public: static set(int y) {
1
by: Eduardo Suárez | last post by:
Hi, i have tried to understand how static variables work on a dynamic library, but there's a point i can't see. * Is the data segment (where static variables live, please confirm) copied for...
3
by: Datta Patil | last post by:
Hi , #include<stdio.h> func(static int k) /* point2 : why this is not giving error */ { int i = 10 ; // static int j = &i ; /* point 1: this will give compile time error */ return k; } /*...
4
by: Gery D. Dorazio | last post by:
Gurus, If a static variable is defined in a class what is the scope of the variable resolved to for it to remain 'static'? For instance, lets say I create a class library assembly that is...
5
by: Scott Starker | last post by:
Is there anyway to do this? Every time any button is click inside class Form1, MyButtomArray.CharArray (MyButtomArray is a class) gets set (or reset) (bool). Once this is done the class TEC gets...
6
by: depalau | last post by:
I'm running into some issues on maintaining a static variable across the lifetime of a web service and I was wondering if anyone could help. Background: We have developed a C#/1.1 web service...
3
by: Samuel R. Neff | last post by:
Is there any way to declare a static variable within a generic type definition and have that variable be shared across all constructed generic types? For example, how can I modify this code: ...
9
by: LamSoft | last post by:
Class B { public B() {} } Class A : B { public static string ABC = "myABC"; public A() {} }
37
by: minkoo.seo | last post by:
Hi. I've got a question on the differences and how to define static and class variables. AFAIK, class methods are the ones which receives the class itself as an argument, while static methods...
19
by: Steven Blair | last post by:
Hi, I have webservice which holds a static variable. I send my first message into the webservice and the static variable gets a value. If I queried the webservice at a later time (say after 1...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.