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

推荐订阅源

S
Secure Thoughts
S
Securelist
P
Proofpoint News Feed
D
DataBreaches.Net
Cisco Talos Blog
Cisco Talos Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Project Zero
Project Zero
A
About on SuperTechFans
罗磊的独立博客
WordPress大学
WordPress大学
月光博客
月光博客
Latest news
Latest news
C
Cyber Attacks, Cyber Crime and Cyber Security
GbyAI
GbyAI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - 三生石上(FineUI控件)
F
Fortinet All Blogs
W
WeLiveSecurity
Attack and Defense Labs
Attack and Defense Labs
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Privacy International News Feed
AI
AI
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Stack Overflow Blog
Stack Overflow Blog
M
MIT News - Artificial intelligence
Help Net Security
Help Net Security
T
Tor Project blog
V
Vulnerabilities – Threatpost
C
Cisco Blogs
I
Intezer
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
MyScale Blog
MyScale Blog
雷峰网
雷峰网
MongoDB | Blog
MongoDB | Blog
Forbes - Security
Forbes - Security
V
V2EX
Apple Machine Learning Research
Apple Machine Learning Research
T
Threat Research - Cisco Blogs
B
Blog RSS Feed
博客园 - 叶小钗
N
News and Events Feed by Topic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Simon Willison's Weblog
Simon Willison's Weblog
C
CERT Recently Published Vulnerability Notes
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
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 AsyncCallback The Windows Control 为开通http://beta.zooomr.com/的Pro帐户用的 标准代码页列表 winmine cheat Read MP3 Header Info
AsyncCallback The Windows Control
-==NoWay.==- · 2006-07-17 · via 博客园 - -==NoWay.==-

在项目中经常有装入大批量数据,需要显示进度。

但Windows Control不是线程安全的。

在装库过程中,可能要对Control进行操作,此时,如果随意拖动窗体。

主进程就无法进行对Control的Redraw.

所以就要采用异步的方法。

  private SortedList sl = null;
  private const int  TEST_COUNT = 10000;

  private void button1_Click(object sender, System.EventArgs e)
  {
   mi = new MethodInvoker(DoWork);
   mi.BeginInvoke(new AsyncCallback(DoneWork), null);
  }
  private void DoWork()
  {
   sl = new SortedList();
   InitialPB(TEST_COUNT);
   for (int i =0;i<TEST_COUNT;i++)
   {
    sl.Add(i,"NoWay" + i.ToString());
    Thread.Sleep(100);
    RefreshText("NoWay" + i.ToString());
    RefreshPB(1);
   }
   
  }
  private void InitialPB(int max)
  {
   if( InvokeRequired )
   {
    this.Invoke( new IntDelegate(InitialPB), new object [] { max } );
    return ;
   }

   progressBar1.Maximum = max ;
   progressBar1.Value = 0;
  }

  private void RefreshText(string item)
  {
   if( InvokeRequired )
   {
    this.Invoke( new StringDelegate(RefreshText), new object [] { item } );
    return ;
   }

   this.textBox1.Text = item;
  }

  private void RefreshPB(int Value)
  {
   if( InvokeRequired )
   {
    this.Invoke( new IntDelegate(RefreshPB), new object [] {Value} );
    return ;
   }

   progressBar1.Value+=Value;
  }

  private void DoneWork(IAsyncResult result)
  {
   if( InvokeRequired )
   {
    Invoke(new AsyncCallback(DoneWork), new Object [] { result } );
    return ;
   }
   MessageBox.Show("Done!");
  }

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

  private MethodInvoker mi= null;

  private delegate void IntDelegate(int num);
  private delegate void StringDelegate(string str);