委托 跟 线程

1.委托

 1 #region 委托
 2         /// <summary>
 3         /// 输出委托
 4         /// </summary>
 5         /// <param name="msg"></param>
 6         private delegate void OutputDelegate(string msg);
 7 
 8         /// <summary>
 9         /// 清空委托
10         /// </summary>
11         private delegate void ClearDelegate();
12 
13         /// <summary>
14         /// 文本框输出委托
15         /// </summary>
16         /// <param name="msg"></param>
17         private void TextBoxOutput(string msg)
18         {   
19             if (ConfigCon.IsVisble==false)
20             {
21                 this.textBox1.Dispatcher.Invoke(new OutputDelegate(OutputAction), msg);
22 
23                 this.textBox1.Dispatcher.Invoke(new ClearDelegate(ClearAction));
24                
25             }
26           
27         }
28 
29         /// <summary>
30         /// 文本框输出内容
31         /// </summary>
32         /// <param name="msg"></param>
33         private void OutputAction(string msg)
34         {
35             this.textBox1.AppendText(msg + "\n");
36            // this.textBox1.AppendText("\n");
37             this.textBox1.ScrollToEnd();
38         }
39 
40 
41         /// <summary>
42         /// 文本框清空
43         /// </summary>
44         private void ClearAction()
45         {
46 
47             if (this.textBox1.LineCount > 10000 * 1)
48             {                
49                 this.textBox1.Clear();    
50             }
51             
52                 
53         }
54 
55         #endregion
View Code

2.线程

 1 #region 线程池
 2 
 3         /// <summary>
 4         /// 判断是否在运行线程
 5         /// </summary>
 6         private static bool bRuning = false;
 7         
 8         /// <summary>
 9         /// 线程池
10         /// </summary>
11         private static List<Thread> threadPool = new List<Thread>();
12         /// <summary>
13         /// 判断是否运行线程,使用它来让线程自然终止
14         /// </summary>
15         static volatile bool bRun = false;
16 
17         /// <summary>
18         /// 初始化线程池
19         /// </summary>
20         private void ThreadPoolIni()
21         {
22            
23 
24             if (RdbReader.Start(ConfigCon.RedisCon, 0) != true)
25             {               
26                 TextBoxOutput("redis服务连接失败!  【" + DateTime.Now.ToString() + "】\n");
27                 return;
28             }
29 
30             List<TForward> forwards = new List<TForward>();
31             forwards = TForwardDal.GetForwards();         
32 
33             threadPool.Clear();          
34             foreach (TForward forward in forwards)
35             {   
36                 ThreadPool.QueueUserWorkItem(SendForwardList, forward);  
37             }   
38             GC.Collect();
39             
40 
41         }
42 
43         /// <summary>
44         /// 启动线程池中的线程
45         /// </summary>
46         private void ThreadStart()
47         {
48             bRun = true;           
49             foreach (Thread thread in threadPool)
50             {
51                 thread.Start();
52             }
53         }
54 
55         /// <summary>
56         /// 停止线程池中的线程
57         /// </summary>
58         private void ThreadStop()
59         {
60             bRun = false;
61         }
62 
63         /// <summary>
64         /// 返回线程池大小
65         /// </summary>
66         /// <returns>线程池大小</returns>
67         private int ThreadSize()
68         {
69             return threadPool.Count;
70         }
71 
72         #endregion
View Code

 

posted @ 2017-08-04 15:41  <--青青子衿-->  阅读(84)  评论(0编辑  收藏  举报
// /**/ // 在页脚Html代码 引入 // function btn_donateClick() { var DivPopup = document.getElementById('Div_popup'); var DivMasklayer = document.getElementById('div_masklayer'); DivMasklayer.style.display = 'block'; DivPopup.style.display = 'block'; var h = Div_popup.clientHeight; with (Div_popup.style) { marginTop = -h / 2 + 'px'; } } function MasklayerClick() { var masklayer = document.getElementById('div_masklayer'); var divImg = document.getElementById("Div_popup"); masklayer.style.display = "none"; divImg.style.display = "none"; } setTimeout( function () { document.getElementById('div_masklayer').onclick = MasklayerClick; document.getElementById('btn_donate').onclick = btn_donateClick; var a_gzw = document.getElementById("guanzhuwo"); a_gzw.href = "javascript:void(0);"; $("#guanzhuwo").attr("onclick","follow('33513f9f-ba13-e011-ac81-842b2b196315');"); }, 900);