zoukankan      html  css  js  c++  java
  • .NET WINFORM 多线程编程

    1,创建委托:

      private delegate void CustomPropertyLoad1(List<CustomProperty> properties, FlowLayoutPanel container);

      2个参数用来传递方法中用到的界面控件。

    2.   Thread LoadCustomPropertyThread;

            private Thread LoadCustomProperties(List<CustomProperty> properties)
    {
    if (properties != null)
    {

    var thread
    = new Thread(new ThreadStart(delegate()
    {
    try
    {
    var count
    = 0;
    do
    {
    if (this.InvokeRequired)
    {
    this.Invoke(new CustomPropertyLoad1(LoadCustomPropertiesUI), this.editproperties, this.flowLayoutPanel1);
    break;
    }
    Thread.Sleep(
    100);
    count
    ++;
    }
    while (count < 10);
    }
    catch
    {

    }
    }));
    thread.IsBackground
    = true;
    thread.Start();
    return thread;
    }
    else
    {
    this.flowLayoutPanel1.Controls.Clear();
    }
    return null;
    }

      

            private void LoadCustomPropertiesUI(List<CustomProperty> p, FlowLayoutPanel container)
    {
    Application.DoEvents();
    container.SuspendLayout();
    var count
    = p.Count();
    for (var i = 0; i < count; i++)//增量添加自定义属性
    {
    var customPropertyPanel
    = new CustomPropertyPanel();
    customPropertyPanel.Property
    = p[i];
    customPropertyPanel.Width
    = container.Width - 20;
    container.Controls.Add(customPropertyPanel);

    }
    container.ResumeLayout();
    }

      

    LoadCustomPropertyThread = LoadCustomProperties(this.editproperties);

  • 相关阅读:
    PM对功能模块的说明
    第四个迭代目标
    第三个迭代任务
    第三个迭代目标
    记账本状态图
    记账本数据流图
    记账本ER图
    记账本用例图
    第二个迭代目标
    记账本时序图
  • 原文地址:https://www.cnblogs.com/netact/p/2127765.html
Copyright © 2011-2022 走看看