0

I have sample windows app written in C#.net and I have a global variable which i need to share to different applications when my app is running.

Below is code :

using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Test
{
    public partial class Form1 : Form
    {
        public string GlobalValue = string.Empty;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            if((textBox1.Text!="") && (textBox1.Text!=null))
            {
                GlobalValue = textBox1.Text.ToString();
            }

        }
    }
}

In above code, user enters a value in text box and GlobalValue is updated on button click event.

I want to share the value of variable GlobalValue across different applications and how do i do it in C#. Suppose I'm running 3D Mark along with my sample app and this GlobalValue should be accessible to 3D Mark app or any other app.

I don't won't to use the registry to store the value.. need some other way

If an example is given, it will be really helpful for me.

thanks,

sia
  • 1,872
  • 1
  • 23
  • 54
  • Write GlobalValue to file\registry\database and so on and other apps should read it. – Renatas M. Oct 27 '14 at 14:51
  • @Reniuz - but as per requirement i'm not to suppose to use registry.. so need other alternative. – sia Oct 27 '14 at 14:57
  • So why didn't you mentioned so important thing in question? Other option use any communication protocol to push updated value to clients/listeners(other apps) – Renatas M. Oct 27 '14 at 15:02
  • @Reniuz - i have updated in the question later. – sia Oct 27 '14 at 15:09
  • Take a look at this: http://stackoverflow.com/a/7894262/367764 answer, probably the thing you are looking for. – galenus Nov 02 '14 at 19:08

2 Answers2

0

You should read this microsoft article about interprocess communication and pick the best solution for your use case.

To sum up:

File mapping is a easy way to share information (make your data looks like a file) but you need to use primitive for inter process synchronisation.

Pipe and windows sockets would help you to overcome the synchronisation issue but you'll need to have proper code in all applications needing to access (read or write) the variable.

kamaradclimber
  • 2,479
  • 1
  • 26
  • 45
0

I hope the below information will be helpful

You can use Windows Register to save any value you want.