Solved

Isolating Application.Run instances

Posted on 2010-09-17
5
385 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can I command line build a C# application? 6 40
MailAddress in vb 4 29
JSON Deserialize issue 6 26
Where does legacy ASP.NET initialize language? 2 19
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

792 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