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);
}
}
}
}
}