首页 新闻 会员 周边 捐助

weifenluo.winformsui.docking thread 问题

0
悬赏园豆:10 [待解决问题]

using SampleWorkspacesApp.WorkSpaces;
using System.Threading;
using System.Windows.Forms;
namespace SampleWorkspacesApp
{
    public partial class DummyToolbox : WorkItemDockContent
    {
        public DummyToolbox() :
            base(EWorkItemContentType.ToolWindow)
        {
            InitializeComponent();
        }

        public override void Save(System.Xml.XmlTextWriter xmlWriter)
        {
            xmlWriter.WriteStartElement(typeof(DummyToolbox).Name);
            xmlWriter.WriteEndElement();
        }

        private void DummyToolbox_Load(object sender, System.EventArgs e)
        {


            Thread thre = new Thread(new ThreadStart(test));
            thre.Start();

        }
        void test()
        {
            if (this.IsHandleCreated)
            {
                for (int i = 0; i < 1000; i++)
                {

                    if (label1.IsHandleCreated && this.IsHandleCreated)
                    {
                        this.Invoke((MethodInvoker)delegate
                        {

                            label1.Text = i.ToString();

//"在创建窗口句柄之前,不能在控件上调用 Invoke 或 BeginInvoke"

//线程没有结束前关闭 出错

//代码在github.com DockedWorkspaces 找一下,需要的可以发邮件给我554961776@qq.com

                        });
                    }
                    Thread.Sleep(10);


                }

            }
        }
    }
}

问题补充:

http://download.csdn.net/detail/windowsxpaccp/5335581

代码下载地址

window5549-accp的主页 window5549-accp | 初学一级 | 园豆:117
提问于:2013-05-06 11:58
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册