简体   繁体   English

C#中的共享对象,可以供其他程序使用

[英]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? 我应该使用什么结构在C#中创建一个可以在其他第三方软件或程序中使用的共享库?

Example: 例:

My program reads a abc.xml and I need to share data read from this file. 我的程序读取abc.xml,我需要共享从该文件读取的数据。 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. 我还有另一个perl脚本,需要读取此共享数据,因此我想知道在这种情况下最好的方法是什么。

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. 我不确定是否可以从Perl中访问它们,但是可以从多个.NET应用程序中进行访问。

You need to open you file in both C# and Perl in a non blocking mode. 您需要以非阻塞模式在C#和Perl中打开文件。 In C# you can use: 在C#中,您可以使用:

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. 您可以为此查看FileSystemWatcher类。

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. 更好的做法是将此类数据视为一个应用程序专用,并使用使用web服务的显式API(例如,应用程序间通信)。

I may be missing something here. 我可能在这里错过了一些东西。

But isn't a FILE itself a shared resource that can be accessed across programs? 但是FILE本身不是共享的资源,可以跨程序访问吗? If a perl script needs the file why not just read it in as part of perl script? 如果perl脚本需要文件,为什么不将其作为perl脚本的一部分读取呢?

What is the advantage you are gaining from loading it in .net? 通过将其加载到.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? 还是编写一个Perl脚本可以查询的.net服务?

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, 如果您无法用一种语言来完成您想做的一切,又不想弄清楚,为什么不使用powershell或批处理文件将它们捆绑在一起,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#中的共享对象将在python脚本中使用 - shared object in C# to be used in python script 如何指定可以使用C#在文本框中进行书写的书写对象(键盘/条形码扫描仪)? - How to specify which writing object (keyboard/barcode scanner) can be used to write in textbox using C#? 定义一个C#方法,它接受任何可以与方括号一起使用的对象 - Define a single C# method which accepts any object that can be used with square brackets Asp Net Core C#中的哪种数据类型可用于捕获Angular的blob对象? - Which data type in Asp Net Core C# can be used to catch Angular's blob object? 你能制作一个 C# 程序,它不能访问除安装文件夹以外的任何本地文件系统吗? - Can you make a C# program which can not access to any local file system other than the folder it is installed? 如何减少此程序中使用的 C# 代码量? - How can I reduce the amount of C# code used in this program? 硒可以在独立的C#程序中使用吗? - Can Selenium be used in a stand-alone c# program? C# 中可以使用哪种类型签名来记忆泛型方法? - Which type signature can be used to memoize a generic method in C#? 创建可以在c#和c ++中使用的c#dll - create c# dll which can be used from both c# and c++ 当我尝试删除正在使用的文件时,C#程序冻结 - C# program freezes when I try to delete file which is being used
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM