Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.24/5 (3 votes)
See more:
Hi I am trying to develop a program to crash a large program that runs a big machine.
I know it sounds bad to crash it but if for some reason the machine gets out of hand we can stop the machine but it doesn't stop the program.The C# writes to a plc so the program runs the machine.Windows 10 isn't an option cuz we all hate it.

What I have tried:

I really don't know where to start. I am new to c# and programming in general.Thanks in advance
Posted
Updated 22-Jun-18 6:59am
v2
Comments
[no name] 22-Jun-18 12:43pm    
Pull the plug.
Dave Kreskowiak 22-Jun-18 13:23pm    
You can stop the machine but the PLC code keeps running like the machine is running?

From just your description, it sounds like you've got much bigger problems than just shutting down the app. You've got sensor and PLC code problems. It sounds like the PLC has no clue what state the machine is at any point and just keeps running like everything is fine. That's bad.

Works starting with windows XP, not available in win 2000 or lower:

This is the quickest way to do it:
Process.Start("shutdown","/s /t 0");


Otherwise use P/Invoke or WMI like others have said.

Edit: how to avoid creating a window
var psi = new ProcessStartInfo("shutdown","/s /t 0");
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
Process.Start(psi);

thanks to Pop Catalin
.net - How to shut down the computer from C# - Stack Overflow[^]
 
Share this answer
 
Comments
Codingnow20 25-Jun-18 11:37am    
thanx
Clifford Nelson 25-Jun-18 15:51pm    
Glad it worked.
Upgrade it to Windows 10.
 
Share this answer
 
Firstly you need a good understanding of programming in general, how programs are built, how they run, and how they react to external events. Next you need a good understanding of the Operating System that your program will run on, and how you can interact with it and with other running programs. Then you need a programming language that lends itself to this sort of task, C or C++ are likely better choices than C#. Finally you need to understand that if the big program is not running correctly, or the machine is not running correctly, your 'crasher' will most likely not run correctly.

And for the record, if you stop the machine how does this other program keep running?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900