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();
                }
            }
    
  • 相关阅读:
    二进制&bitset(未完成)
    Python接口测试课程(第四天)-接口测试框架实现
    Python接口测试课程(第三天)-接口安全验证,参数化及断言
    Python接口测试课程(第二天)-接口测试快速实践
    {title}
    Python自动化测试面试题-接口篇
    Python自动化测试面试题-Selenium篇
    unittest使用signal信号量
    Selenium使用ChromeOptions启动参数
    Selenium执行Javascript脚本使用参数和返回值
  • 原文地址:https://www.cnblogs.com/gengyuanchao/p/2827247.html
Copyright © 2011-2022 走看看