First you must learn the basics of c# and probably of Visualstudio, there is no way to skip steps, this will only make the path harder. After learning about:
- Variables
- Function
- Classes
- Object orientation
- About methods practices in csharp classes
- Build a Helloworld with Console and one with Windows Form
So by doing this you can start studying native (and non-native libraries).
After having studied the basics, an example of killing an application that is what you want, to block is required the kill
, will require an "infinite loop":
new Thread(() =>
{
while (true)
{
Thread.Sleep(100);
Process[] ps = Process.GetProcessesByName("NOME DO PROCESSO QUE DESEJA BLOQUEAR");
foreach (Process pr in ps)
{
pr.Kill();
pr.Close();
}
}
}).Start();
Note: Change the "NOME DO PROCESSO QUE DESEJA BLOQUEAR"
by the name of the process you want to block.
With the Process.GetProcessesByName
you can take the process by name, then with the foreach
you can list all open instances and "kill them", probably it should stay within an infinite loop in another Thread
.
Being a console I think it will not be necessary to Thread, unless you want to put Input commands, but just happen to block (I could not test):
using System;
public class BloquearProcessos
{
public static void Main()
{
while (true)
{
Thread.Sleep(100);
Process[] ps = Process.GetProcessesByName("NOME DO PROCESSO QUE DESEJA BLOQUEAR");
foreach (Process pr in ps)
{
pr.Kill();
pr.Close();
}
}
}
}
Chance to be a Form
visual studio itself already creates a basic structure, but if you don’t know where to apply the code follows an example:
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Thread eventThread = new Thread(() =>
{
while (true)
{
Thread.Sleep(100);
Process[] ps = Process.GetProcessesByName("NOME DO PROCESSO QUE DESEJA BLOQUEAR");
foreach (Process pr in ps)
{
pr.Kill();
pr.Close();
}
}
});
eventThread.IsBackground = true;
eventThread.Start();
}
}
}
Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?
– Maniero