Solved

Isolating Application.Run instances

Posted on 2010-09-17
5
381 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
Comment Utility
...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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now