Inter Process Communication in C#

Introduction

Alright, so you guys might know about the famous web-browser, Google Chrome. One remarkable thing in this (pretty) simple looking application is the use of a programming technique called IPC or Interprocess Communication; with IPC you can communicate with another process without invoking and other third party events. One of the most irritating about .Net is that the app freezes if it is trying to communicate with a web-service. With IPC we can eradicate this problem.

What can you do with it?

So, lets first take an example of what exactly we can do with this: suppose that you have a licensing application named LicMan.exe and a processing app called LicPro.exe. LicMan has the UI and every other part of standard human interference. And LicPro.exe just takes the License Key provided and then processes it and sends it back to LicMan.exe for display. This way the app would not hang and you have a happy customer :-)

Lots of bad ways of doing IPC:

  • Shared Memory: Difficult to manage and set-up.
  • Shared Files / Registry: Very slow doe to the writing & reading to/from disk. Difficult to manage as well.
  • SendMessage / PostMessage: Locks up the UI thread while the message is processed. Messages are limited to integer values. Can't communicate from a non-admin process to a admin process. Assumes that your process has a window. 

How To End Process Using C#

end process

This is a very nice tutorial and very useful in the same time and i am not going to make it so hard since you should learn the basics first ok now you need to create a new project and name the project and after creating the project you should set up the normal things you do and after that i am using a button and a text box so just go ahead and add a button and text box and change the text property of button to "end process" or whatever now when you put the process name in the text box and press the button that process will be ended .

here is the codes

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

//Author : Mohamed Shimran
//Blog : Http://www.ultimateprogrammingtutorials.blogspot.com

namespace EndProcess
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
       
        private void button1_Click(object sender, EventArgs e)
        {

            Process[] ps = Process.GetProcesses();
            foreach (Process p in ps)
            {
                if (p.ProcessName.ToLower() == textBox1.Text )
                {
                    p.Kill();
                }

            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        
    }
}


enjoy and try to make it more stable since its not stable