?
Solved

Isolating Application.Run instances

Posted on 2010-09-17
5
Medium Priority
?
393 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

752 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