-
February 11th, 2010, 12:56 AM
#1
Shared segment in c#
Hi,
Does anyone know how to have a shared segment in a c# dll?? Im trying to share the values of some variables in a dll accross two different exes.
Theres heaps of stuff on doing it in c++ but can find anything on c#.
c++ uses:
pragma# data_seg(".shared")
Any ideas would be appreciated.
-
February 11th, 2010, 08:05 AM
#2
Re: Shared segment in c#
Originally Posted by Andre2
Hi,
Does anyone know how to have a shared segment in a c# dll?? Im trying to share the values of some variables in a dll accross two different exes.
Theres heaps of stuff on doing it in c++ but can find anything on c#.
c++ uses:
pragma# data_seg(".shared")
Any ideas would be appreciated.
Well...I'm not sure there is a similar concept in .NET. This wouldn't be a limitation of C# but a limitation on the runtime. I think the AppDomain concept might actually physically prevent such a sharing. You could think of alternatives though. When you think about it with C# and .NET we are encouraged to think slightly differently from how we would have in pure native C++ applications. If you approach it from an object-oriented approach what you could have is a class defined in the dll. That class could expose a property that would provide access to the shared data to the executables that use the dll. You would have to synchronise access to the data somehow. If the data is persisted in the database, the database should handle that for you. If the data is volatile then you would need to implement a simple but effective synchronisation mechanism.
-
February 11th, 2010, 11:36 AM
#3
Re: Shared segment in c#
In .net you typically share data via .net remoting, or more recently can use a WCF web service (since a WCF service can be hosted from any exe).
You can also share data using the traditional interprocess communication techniques such as memory mapped files, named pipes, etc. but you'll need to pinvoke to the appropriate Win32 api's in order to do it this way.
-
February 11th, 2010, 12:04 PM
#4
Re: Shared segment in c#
Originally Posted by Arjay
In .net you typically share data via .net remoting, or more recently can use a WCF web service (since a WCF service can be hosted from any exe).
You can also share data using the traditional interprocess communication techniques such as memory mapped files, named pipes, etc. but you'll need to pinvoke to the appropriate Win32 api's in order to do it this way.
I would go for WCF hosted in IIS. That way you still just have your DLL with the implementation of the WCF service. Ideally your service should be stateless so you would have to persist any state to something like a database.
-
February 11th, 2010, 01:08 PM
#5
Re: Shared segment in c#
Just wanted to mention that unlike the older web services, WCF doesn't have to be hosted in IIS. WCF can be hosted in IIS, a console app, winforms app, WPF app, etc.
As such, it can be used as a communication layer between two applications (kind of like pragma# data_seg(".shared") but in an upscale way).
-
February 12th, 2010, 02:56 AM
#6
Re: Shared segment in c#
Also, you can always use windows API to create shared memory trought P/Invoke.
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|