Problem running two instances of an application

Jun 12, 2008 at 3:49 PM

Hello,
    I'm writing some tests where I need to start our application twice and then check that they interact correctly. The problem I have is that I have just a single process but 2 instances of our application. This is the same as Word and if you run the following code you will have the same problem:

Application word1 = Application.Launch("Winword.exe");
Application word2 = Application.Launch("Winword.exe");

When I try to use the second object reference I find that it returns an exception. For example:

String s = word2.Name;

 

Looking at the word2 object many of the properties are not set due to exceptions being thrown.

Is there another way that I can lauch the second instance of the application?

Thanks,
Paul.

 

 

 







Coordinator
Jun 13, 2008 at 8:57 PM
There should be no reason for not being able to do this. What is the exception that you are getting?
Jun 16, 2008 at 9:39 AM


viveksingh wrote:
There should be no reason for not being able to do this. What is the exception that you are getting?



Hi,
The exception I'm getting is:

WPFTestApp.Test.ExercisingWhite.CloseUsingModalXButton:
System.InvalidOperationException : Process has exited, so the requested information is not available.
TearDown : System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
  ----> System.NullReferenceException : Object reference not set to an instance of an object.

If I look at word2 values such as HasExit are set to true and many of the other properties have thrown exceptions.
Coordinator
Jun 16, 2008 at 3:14 PM
Are your word instances running when you get the exception. Application is just a wrapper over Process object in .NET (as far as this issue is concerned).
Jun 19, 2008 at 9:57 AM


viveksingh wrote:
Are your word instances running when you get the exception. Application is just a wrapper over Process object in .NET (as far as this issue is concerned).



Yes, both instances are running when the exception occurs. The second instance appears to being running correctly, I suspect that White is having problems getting hold of the second instance when it starts up.
Coordinator
Jun 21, 2008 at 3:26 PM
Since I am unable to reproduce the problem, can you please try this same thing using Process object in .NET.
Jun 23, 2008 at 10:43 AM


viveksingh wrote:
Since I am unable to reproduce the problem, can you please try this same thing using Process object in .NET.



I get the same exceptions as before. The code that I ran is as follows:

Process word1 = new Process();
Process word2 = new Process();

 

word1.StartInfo.FileName =

@"C:\Program Files\Microsoft Office\Office12\Winword.exe";
word1.Start();
string mainTitle1 = word1.MainWindowTitle;

 

word2.StartInfo.FileName =

@"C:\Program Files\Microsoft Office\Office12\Winword.exe";
word2.Start();
string mainTitle2 = word2.MainWindowTitle;

 

After starting the first instance of Word I can get the value of MainWindowTitle ok, but when the second instance is started and I try to get the MainTitleWindow value for the second instance I get an InvalidOperationException.