Solved

Isolating Application.Run instances

Posted on 2010-09-17
5
384 Views
Last Modified: 2013-12-16
I have a console program that starts multiple instances of an application program App. It launches each instance of App via Application.Run.

The problem I'm having is that App includes static variables and these are being shared between instances. I need to isolate them so that each instance uses its own set of static variables.

Ideas? I'm using C# 4.0 / VS 2010.
0
Comment
Question by:BlearyEye
  • 3
5 Comments
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 33703923
...each instance uses its own set of static variables.
Static variables, by definition, are shared between every instance of a given class - if you want to avoid this behavior you must use non-static member variables.
Why are you calling Application.Run() more than once? There may be a better alternative...
0
 
LVL 1

Author Comment

by:BlearyEye
ID: 33704231
App is a machine controller. It's set up so that it can handle multiple machines. Each instance that's started with Application.Run() is supposed to control a different machine.

The dashboard is intended to control which instance of App the user sees; and it also displays summary status information from each instance.

Application.Run() seemed like a reasonable way to do this, until I ran into this issue with static variables.

Switching away from static variables would be hard. Replacing static variables with vectors indexed by instance number is one option, I suppose; but it's not a very pleasant one since there are a lot of static variables.
0
 
LVL 8

Assisted Solution

by:Gururaj Badam
Gururaj Badam earned 500 total points
ID: 33704282
Since the controller is the main thread all the Application.Run are kind of belong to that main thread. The other way to do this is may you should use Process.

The MSDN reference will give you sample code on how you can use Process

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx
0
 
LVL 1

Author Comment

by:BlearyEye
ID: 33704595
If I go with separate processes, I'll need to implement communication between them. I guess I'll look into whether remoting will give me the isolation I need ...
0
 
LVL 1

Accepted Solution

by:
BlearyEye earned 0 total points
ID: 33794472
So here's what I wound up doing.

- I launch each instance on its own thread.
- I make each instance a WCF server to receive comm from the dashboard client
- I also make the dashboard a WCF server to receive comm from the instances. This was because WCF callback seems to be designed for the case of one server with multiple clients, not multiple servers with one client
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question