3

I'd like to have a List<int> that multiple instances of my application can access. At the moment I can cheat and use a global mutex but that hardly would work well after 10K ints. How do I get multiple instances of a program to share a list?

  • read/write or readonly across apps? – Jamiec Feb 20 '14 at 08:54
  • 1
    do you really mean instances of your applications and not threads inside of your application right? Why not using queues? – Rafa Feb 20 '14 at 08:56
  • Yes I do mean instance. How do I use a queue? I'm trying to avoid using a database otherwise i'll throw something together with redis –  Feb 20 '14 at 09:10

1 Answers1

2

An easy way to do that is to put this data in a custom windows service.

Host in this service the data you want to share and provide access to this data using any kind of IPC. The simplest is WCF.

Another method may consists in having only one instance of the application. Instead of having on form in your app, manage multiple forms as separate "pseudo" instances. When firing the app again, check if the app is already launched and trigger a message to this app.

Lastly, as Raja suggest, use a queue to share data between apps. But this requires more information about how and when the list is populated.

Steve B
  • 34,941
  • 18
  • 92
  • 155
  • I never used a windows service or WCF. Is it ridiculously easy? Essentially I'll add int or long (MAYBE string but i doubt it) to a list or set and I really need to only know if the id is in the set or not. I might use redis but I'm trying to keep it simple –  Feb 20 '14 at 09:13
  • Maybe [this question](http://stackoverflow.com/questions/56121/ipc-mechanisms-in-c-sharp-usage-and-best-practices) may help? There are many ways of making apps communicate together, including WCF, Remoting, Sockets, ... WCF is not as complicated, but you have a small learning curve to make it works. – Steve B Feb 20 '14 at 09:28