Beispiel #1
0
        /// <summary>
        /// Remove the specific Download File/Data from the DCC File List
        /// </summary>
        private void RemoveDCCFile(DccFileStruct dcc)
        {
            if (this.InvokeRequired)
            {
                RemoveDCCFileDelegate remove = new RemoveDCCFileDelegate(RemoveDCCFile);
                this.Invoke(remove, new object[] { dcc });
            }
            else
            {
                foreach (ListViewItem l in dccFileList.Items)
                {
                    if (l.Tag.ToString() == dcc.ListingTag.ToString())
                    {
                        //close enough for a match, use this file
                        dccFileList.Items.Remove(l);
                        //remove the item from dccFiles
                        try
                        {
                            if (dcc.FileStream != null)
                            {
                                dcc.FileStream.Flush();
                                dcc.FileStream.Close();
                            }

                            if (dcc.Thread != null)
                                if (dcc.Thread.IsAlive)
                                    dcc.Thread.Abort();

                            if (dcc.Socket != null)
                                if (dcc.Socket.Connected)
                                    dcc.Socket.Close();

                            if (dcc.ListenerSocket != null)
                            {
                                dcc.ListenerSocket.Stop();
                                dcc.ListenerSocket = null;
                            }

                            if (dcc.ListenerThread != null)
                            {
                                dcc.keepListening = false;
                            }

                            if (dcc.timeoutTimer != null)
                            {
                                dcc.timeoutTimer.Stop();
                                dcc.timeoutTimer = null;
                            }
                        }
                        catch { }

                        dccFiles.Remove(dcc);

                        return;
                    }
                }
            }
        }
        /// <summary>
        /// Remove the specific Download File/Data from the DCC File List
        /// </summary>
        private void RemoveDCCFile(DccFileStruct dcc)
        {
            if (this.InvokeRequired)
            {
                RemoveDCCFileDelegate remove = new RemoveDCCFileDelegate(RemoveDCCFile);
                this.Invoke(remove, new object[] { dcc });
            }
            else
            {
                foreach (ListViewItem l in dccFileList.Items)
                {
                    if (l.Tag.ToString() == dcc.ListingTag.ToString())
                    {
                        //close enough for a match, use this file
                        dccFileList.Items.Remove(l);
                        //remove the item from dccFiles
                        try
                        {
                            if (dcc.FileStream != null)
                            {
                                dcc.FileStream.Close();
                            }

                            if (dcc.Thread != null)
                                if (dcc.Thread.IsAlive)
                                    dcc.Thread.Abort();

                            if (dcc.Socket != null)
                            {
                                if (dcc.Socket.Connected)
                                    dcc.Socket.Close();

                                dcc.Socket = null;
                            }

                            if (dcc.ListenerSocket != null)
                            {
                                dcc.ListenerSocket.Stop();
                                dcc.ListenerSocket = null;
                            }

                            if (dcc.ListenerThread != null)
                            {
                                //dcc.keepListening = false;
                            }

                            if (dcc.timeoutTimer != null)
                            {
                                dcc.timeoutTimer.Stop();
                                dcc.timeoutTimer = null;
                            }

                            dccFiles.Remove(dcc);

                        }
                        catch (SocketException se)
                        {
                            System.Diagnostics.Debug.WriteLine("remove dcc socket error:" + se.Message);
                        }
                        catch (Exception ee)
                        {
                            System.Diagnostics.Debug.WriteLine("remove dcc error:" + ee.Message);
                        }

                        return;
                    }
                }
            }
        }