zoukankan      html  css  js  c++  java
  • 线程和委托

    #region 线程
            //线程一的方法
            private void CrossThreadFlush()
            {
                while (true)
                {
                    if (bFirstThread)
                    {
                        continue;
                    }
                    else
                    {
                        //将代理绑定到方法 
                        FlushClient fc = new FlushClient(threadFunFirst);
                        //this.BeginInvoke(fc);//调用代理
                        lvListView.Invoke(fc);
                        bFirstThread = true;
                    }
                }
            }
    
            //线程一的方法:开启ListView的虚拟模式
            private void threadFunFirst()
            {
                //虚拟模式绑定
                strList.Clear();
                //imageList1.Images.Clear();
                if(CurrentCacheItemSource != null)
                {
                    CurrentCacheItemSource = null; 
                }
                string[] astrPath = Directory.GetFileSystemEntries(tNode.Name);
    
                foreach (string strPath in astrPath)
                {
                    if (clManageFile.IsHidden(strPath))
                    {
                        continue;
                    }
                    strList.Add(strPath);
                }
                lvListView.VirtualListSize = strList.Count;
                lvListView.VirtualMode = true;
            }
    
            //线程二的方法:控制线程一
            private void threadFunSecond()
            {
                while (true)
                {
                    try
                    {
                        Monitor.Enter(list);
                        iLoopx = list.Count;
                    }
                    finally
                    {
                        Monitor.Exit(list);
                    }
                    Thread.Sleep(100);
                    try
                    {
                        Monitor.Enter(list);
                        iLoopy = list.Count;
                    }
                    finally
                    {
                        Monitor.Exit(list);
                    }
                    if (iLoopx != iLoopy)
                    {
                        continue;
                    }
                    if (tNode != null)
                    {
                        if (tNode.Checked)
                        {
                            bFirstThread = false;
                            list.Clear();
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
    
    ListBox listbox;
            StreamWriter sw;
            public Service(ListBox listbox, StreamWriter sw)
            {
                this.listbox = listbox;
                this.sw = sw;
            }
            public void SendToServer(string str)
            {
                try
                {
                    sw.WriteLine(str);
                    sw.Flush();
                }
                catch
                {
                    SetListBox("发送数据失败");
                }
            }
            delegate void ListBoxCallback(string str);
            public void SetListBox(string str)
            {
                if (listbox.InvokeRequired == true)
                {
                    ListBoxCallback d = new ListBoxCallback(SetListBox);
                    listbox.Invoke(d, str);
                }
                else
                {
                    listbox.Items.Add(str);
                    listbox.SelectedIndex = listbox.Items.Count - 1;
                    listbox.ClearSelected();
                }
            }
    
  • 相关阅读:
    syslog远程日志存储/514端口【转】
    干掉僵尸进程
    以太网,IP,TCP,UDP数据包分析【转】
    suricata 的安装编译
    libpcap详解【转】
    蛋疼的经历--wireshark不能启动的问题
    Ubuntu中root用户和user用户的相互切换[转载自93度的饼干]
    OSI七层与TCP/IP五层网络架构详解
    __cplusplus的用法(转)
    IPsec ISAKMP(转)
  • 原文地址:https://www.cnblogs.com/gengyuanchao/p/2827247.html
Copyright © 2011-2022 走看看