Click here to Skip to main content
15,884,537 members

how to remove application from processes(task manager) ?

guendouz bachir asked:

Open original thread
HI everyone...
when I close my application, it always stays with the active processes, each time I remove it from task manager, what do I do?

this is class listen
C#
class Listener
    {
        
        public delegate void lbconnection(string lbconnection);
        public lbconnection lbc;
        Thread thdsHandler;
        public int lport;
        public string lpath;
        
        //Le constructeur de la class Listener
        public Listener(int port,string path,lbconnection lbcc)
        {
            lbc=lbcc;
            lport = port;
            lpath = path;
        }
        public TcpClient handlerSocket;
        public TcpListener tcpListener;
        public void listenerThread()
        {
            //la port d'coute initialisé a 0   
            //int port = 0;
            //la creation de la class tcplistener 
            tcpListener = new TcpListener(new IPEndPoint(IPAddress.Any, lport)); 
            //le debut de l'ecoute on utilisant la methode start
            tcpListener.Start();
            //boucle infini while
            while (true)
            {
                //la method acceptsocket accept chaque client arrivé 
                handlerSocket = tcpListener.AcceptTcpClient();
                if (handlerSocket.Connected)
                {
                    lbc("Connected To Localhost :" + lport + " connected.");
                    //lbConnections.Items.Add("Connected To Localhost :" + lport + " connected.");
                    //lock pour ivite le blocage des clients
                    lock (this)
                    {
                        //alSockets.Add(handlerSocket);
                        Request rqs = new Request(lpath, handlerSocket);
                        //creation d'une thread appeler thdstHandler
                        thdsHandler = new Thread(new ThreadStart(rqs.handlerThread));
                        //thdHandler = new Thread(thdsHandler);
                        //le debut de travail de thread thdstHandler,on utilisant la methode start
                        thdsHandler.Start();
                    }
                }
            }
        }
        //procedure killthread
        public void killthread()
        {
         thdsHandler.Abort();
        }
    }


and the request class

C#
class Request
    {
        //public delegate void Desplaylist(string lv0, string lv1, string lv2, string lv3, string lv4);
        //Desplaylist ds;
        //int tcn = 0; int cc = 0; int sr = 0; int fr = 0; int mc = 0; int rs = 0;
        //public Thread thdHandler;
        //Listener lst;
        public string tbpath;
        public TcpClient tcpclient;
        public Request(string tbpath, TcpClient tcpclient)
        {
           this.tbpath = tbpath;
           this.tcpclient = tcpclient;  
        }
        

        public struct serverinfo
        {
            public string httpversion;
            public string Date;
            public string sinfo;
            public string AcceptRanges;
            public string ContentLength;
            public string Connection;
            public string ContentType;
        };

        // la procedure handleThread fait le traitement de requette arrivé de client 
        public void handlerThread()
        {
            //tcn++;
            //lbConnections.Items.Add("Server Started");
            byte[] clientData = new byte[1024];
            //initialisation d'une socket appele handlesocket 
            //Socket handlerSocket = (Socket)alSockets[alSockets.Count - 1];
            String filename = "";
            String[] verbs;
            NetworkStream ns = tcpclient.GetStream();
            ns.Read(clientData, 0, clientData.Length);
            //handleSocket.Receive(clientData);
            //maitre la requette recus dans un fichier text
            string stringdata = Encoding.ASCII.GetString(clientData);
            File.WriteAllText(tbpath + "\\Request.txt", stringdata);
            verbs = stringdata.Split(" ".ToCharArray());
            // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            filename = verbs[1].Replace("/", "\\");
            if (filename.IndexOf("?") != -1)
            {
                // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                filename = filename.Substring(0, filename.IndexOf("?"));
            }
            if (filename.EndsWith("\\"))
            {
                // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                filename += "index.html";
            }
            filename = tbpath + filename;
            if (!File.Exists(filename))
            {
                //fr++;
                filename = tbpath + "\\Page Not Found.html";
            }
            //if (filename != "\\Page Not Found.html")
            //{
            //    sr++;
            //}
            //ds(Convert.ToString(tcn), Convert.ToString(cc), Convert.ToString(sr), Convert.ToString(fr), Convert.ToString(mc));
            //creation d'une nouvelle class filestream appele fs ouvrir ou cree le fichier ou lien filename
            FileStream fs = new FileStream(filename, FileMode.Open);
            //pointe sur le depart de string 
            fs.Seek(0, SeekOrigin.Begin);
            byte[] fileContents = new byte[fs.Length];
            //Maitre le contenu de (les bites) dans la variable filecontents
            fs.Read(fileContents, 0, (int)fs.Length);
            fs.Close();
            //envoy la reponce ou client on utilisons la methode Send 
            ns.Write(fileContents, 0, fileContents.Length);
            //handleSocket.Send(fileContents);
            serverinfo sinfo = new serverinfo();
            sinfo.httpversion = "HTTP/1.1 200 OK \r\n";
            sinfo.Date = "Dtae: ";
            sinfo.sinfo = "Server: HTTPServer/1 (Windows) HTTP/1.1 \r\n";
            sinfo.AcceptRanges = "Accept-Ranges: bytes \r\n";
            sinfo.ContentLength = "Content-Length: 1564 \r\n";
            sinfo.Connection = "Connection: Close \r\n";
            sinfo.ContentType = "Content-Type: text/html \r\n";
            string servinfo = sinfo.httpversion + sinfo.Date + DateTime.Now.Date + "," + DateTime.Now.Month + " " + DateTime.Now.Year + "  " + DateTime.Now.Hour + " " + DateTime.Now.Minute + " "
                + DateTime.Now.Second + "\r\n" + sinfo.sinfo + sinfo.AcceptRanges + sinfo.ContentLength + sinfo.Connection + sinfo.ContentType + "\r\n" + Encoding.ASCII.GetString(fileContents);
            File.WriteAllText("C:\\www\\Reponse.txt", servinfo);
            //lbConnections.Items.Add(filename);
            //arreté la socket
            ns.Close();
            //handleSocket.Close();
            //procedute killthread qui tue le Thread
            //lst.killthread();
        }
    }


and the click bouton

C#
private void btnStart_Click(object sender, EventArgs e)
        {

            tbPort.ReadOnly = true;
            tbPath.ReadOnly = true;
            //la creation d'une list des socket
            int port = 0;
            port = Convert.ToInt16(tbPort.Text);
            string path = tbPath.Text;
            //alSockets = new ArrayList();
            Listener lst = new Listener(port, path, this.lbconnect);
            //creation d'une thread appeler thdlistener
            thdListener = new Thread(new ThreadStart(lst.listenerThread));
            //le debut de travail de thread...on utilisant la methode start
            thdListener.Start();

            ////////////////////////////////
            btnStart.Enabled = false;
            Resume.Enabled = false;
            Suspend.Enabled = true;
            Stop.Enabled = true;
        }


this is my work and i need to explain me the wrong ...
Tags: C#

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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