?
Solved

Isolating Application.Run instances

Posted on 2010-09-17
5
Medium Priority
?
410 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

840 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