Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by JoeProgram · Dec 22, 2011 at 10:09 PM · reflectionkillprocesssystem.diagnostics

Type 'System.Diagnostics.Process' does not contain a definition for 'CloseMainWindow'

Hello!

I am writing an application in Unity that requires another application to be running. I have been able to successfully start another program from Unity, but I have not been able to close it. I am

 using System.Diagnostics
 ...

 Process p = new Process();
 p.StartInfo.FileName = @"C:\path\to\program.exe";
 p.Start();  // works up to this point
 p.CloseMainWindow(); // throws a compiler error

When I try to run this code, I get a compile error:

Type 'System.Diagnostics.Process' does not contain a definition for 'CloseMainWindow' and no extension method 'CloseMainWindow' of type 'System.Diagnostics.Process' could be found (are you missing a using directive or an assembly reference?)

I get a similar error for the Kill() method.

Both the Kill() and CloseMainWindow() methods are suggested by intellisense in the Monodevelop IDE, and documented in the C# .NET

My theory is that Unity has blocked some features of the .NET framework to prevent a Unity process from shutting down other processes. I have tried using System.Reflection to look inside the Process class, but it isn't working for some mysterious reason (this being my first time using reflection in C#).

How can I close this extra process when the user closes Unity?

Thanks!

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JoeProgram · Dec 22, 2011 at 07:08 PM 0
Share

I have not figured out what is going on, but I have figured out a workaround. Replace:

p.Close$$anonymous$$ainWindow()

with:

p.GetType().Get$$anonymous$$ethod( "Close$$anonymous$$ainWindow" ).Invoke( p, new object[]{} );

Using reflection shows that Close$$anonymous$$ainWindow and $$anonymous$$ill are both still defined, so it seems like a Unity-specific compiler issue.

Another gotcha: If the new process s$$anonymous$$ls focus from Unity, Unity will pause its execution and will not run the Close$$anonymous$$ainWindow method until you click back on it.

avatar image Bunny83 · Dec 23, 2011 at 01:22 AM 0
Share

Hmm, that sounds strange. According to the $$anonymous$$onoCompatibility page this method is supported for standalone builds.

The focus problem is related to your runInBackground - setting which can be configured in the Player settings.

If you're sure that it won't compile in Unity you could create a small sample project which reproduces the problem and file a bugreport so the Unity staff know about the problem.

avatar image JoeProgram · Dec 23, 2011 at 05:38 PM 0
Share

I started to do this process, but then in my debug project Close$$anonymous$$ainWindow() worked perfectly. Something must be obscuring the method in my original project.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by TimK_personal · Oct 28, 2014 at 09:53 PM

It's a million years since this question was asked, but for others (like me) who stumble across this: you are probably not running on a platform that supports these calls, such as the Web Player.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Simple Android project shuts down when user presses the Recent Apps button 1 Answer

Stop Unity Play 1 Answer

How do you kill the Unity.exe process when it will not open a project 2 Answers

Run Terminal Command using System.Diagnostics.Process not working on osx 2 Answers

How to get .exe file to run through script? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges