惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
Intezer
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY
P
Privacy & Cybersecurity Law Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cybersecurity and Infrastructure Security Agency CISA
N
News | PayPal Newsroom
T
Tenable Blog
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Secure Thoughts
P
Privacy International News Feed
IT之家
IT之家
Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
博客园_首页
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
Martin Fowler
Martin Fowler
NISL@THU
NISL@THU
I
InfoQ
D
DataBreaches.Net
有赞技术团队
有赞技术团队
K
Kaspersky official blog
Security Latest
Security Latest
The Register - Security
The Register - Security
Hugging Face - Blog
Hugging Face - Blog
S
Security @ Cisco Blogs
P
Proofpoint News Feed
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
AI
AI
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
N
News and Events Feed by Topic

博客园 - -==NoWay.==-

[转载]使用C#的BitmapData The Open Source iPhone Apps List 一个自动更新的简单实现(通过反射解耦) - -==NoWay.==- - 博客园 Lambda印象 使用WinDBG + SOS调试.Net程序的一般步骤 获取系统信息 魔兽、星际和红警的比较 迟到 年华 一款简单却很非脑力的小游戏 Implementing Virtual Mode with Just-In-Time Data Loading in the Windows Forms DataGridView Control 只因女婿是VB程序员,刚见面就被未来岳父轰出家门 About System.Reflection.Emit InitialInstanceActivator 为开通http://beta.zooomr.com/的Pro帐户用的 AsyncCallback The Windows Control 标准代码页列表 winmine cheat Read MP3 Header Info
AsyncCallback The Windows Control
-==NoWay.==- · 2006-07-21 · via 博客园 - -==NoWay.==-

在项目中经常有装入大批量数据,需要显示进度。
但Windows Control不是线程安全的。
在装库过程中,可能要对Control进行操作,此时,如果随意拖动窗体。
主进程就无法进行对Control的Redraw.
所以就要采用异步的方法。

 1private SortedList sl = null;
 2  private const int  TEST_COUNT = 10000;
 3  private void button1_Click(object sender, System.EventArgs e)
 4  {
 5   mi = new MethodInvoker(DoWork);
 6   mi.BeginInvoke(new AsyncCallback(DoneWork), null);
 7  }

 8  private void DoWork()
 9  {
10   sl = new SortedList();
11   InitialPB(TEST_COUNT);
12   for (int i =0;i<TEST_COUNT;i++)
13   {
14    sl.Add(i,"NoWay" + i.ToString());
15    Thread.Sleep(100);
16    RefreshText("NoWay" + i.ToString());
17    RefreshPB(1);
18   }

19   
20  }

21  private void InitialPB(int max)
22  {
23   if( InvokeRequired )
24   {
25    this.Invoke( new IntDelegate(InitialPB), new object [] { max } );
26    return ;
27   }

28   progressBar1.Maximum = max ;
29   progressBar1.Value = 0;
30  }

31  private void RefreshText(string item)
32  {
33   if( InvokeRequired )
34   {
35    this.Invoke( new StringDelegate(RefreshText), new object [] { item } );
36    return ;
37   }

38   this.textBox1.Text = item;
39  }

40  private void RefreshPB(int Value)
41  {
42   if( InvokeRequired )
43   {
44    this.Invoke( new IntDelegate(RefreshPB), new object [] {Value} );
45    return ;
46   }

47   progressBar1.Value+=Value;
48  }

49  private void DoneWork(IAsyncResult result)
50  {
51   if( InvokeRequired )
52   {
53    Invoke(new AsyncCallback(DoneWork), new Object [] { result } );
54    return ;
55   }

56   MessageBox.Show("Done!")
57;
58  }

59  private void button2_Click(object sender, System.EventArgs e)
60  {
61   mi.EndInvoke(null);
62  }

63  private MethodInvoker mi= null;
64  private delegate void IntDelegate(int num);
65  private delegate void StringDelegate(string str);
66