简体   繁体   中英

shared object in C# which can used by other program

What constructs should I use to create a shared object in C# which can be used in some other third party software or program?

Example:

My program reads a abc.xml and I need to share data read from this file. I have another perl script which needs to read this shared data and hence I want to know what would be best approach for such scenarios.

Thanks.

For serializing access across applications you can look into using a named mutex . I am not sure whether you can access those from Perl but you can certainly do that from multiple .NET applications.

You need to open you file in both C# and Perl in a non blocking mode. In C# you can use:

new FileStream(logfileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

If the file changes, you need to update your deserialized representation and notify your interested parties of the change. You can look into the FileSystemWatcher class for this.

However, this kind of application integration, using a private datastore should be discouraged. It is a better practice to consider such data private to one application, and use explicit APIs using webservices for instance for inter application communication.

I may be missing something here.

But isn't a FILE itself a shared resource that can be accessed across programs? If a perl script needs the file why not just read it in as part of perl script?

What is the advantage you are gaining from loading it in .net?

I know this isn't what you have asked but i don't understand why you are doing what you are doing.

If you want to get enterprisey why not use a message queue? Or write a .net service that the perl script can query?

If you cannot do everything you want in one language and dont want to figure it out, why not use powershell or a batch file to tie it all together,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM