资源简介

C# Winform 利用线程延时创建子窗体并且可跨线程控制主窗体的控件

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ThreadForm
{
    public partial class Form1 : Form
    {
        int count = 0;
        public Form1()
        {
            InitializeComponent();
        }
        public delegate void setShowChartFormInvoke(Form myform);

        public void setShowChartForm(Form myform)
        {
            if (this.InvokeRequired)
            {
                setShowChartFormInvoke _setShowChartFormInvoke = new setShowChartFormInvoke(setShowChartForm);
                this.Invoke(_setShowChartFormInvoke new object[] { myform });
                //Action toDo = () => OpenFrom.Enabled = true;
                //            OpenFrom.Invoke(toDo);               
            }
            else
            {
                myform.Show();
            }
        }

        private void ThreadFunc()
        {
            Form msg = new Form();
            Label lab = new Label();
            lab.Location = new Point(75 50);
            lab.Size = new Size(130 25);
            lab.Text = “当前窗体序号为:“ + count;
            msg.Controls.Add(lab);
            msg.Text = “新窗体“;
            System.Threading.Thread.Sleep(3000);
            setShowChartForm(msg);         
        }

        private void OpenFrom_Click(object sender EventArgs e)
        {
            //OpenFrom.Enabled = false;
            count++;
            ThreadStart Thrad1 = new ThreadStart(ThreadFunc);
            Thread FormThread = new Thread(Thrad1);
            FormThread.Start();
        }

        private void button1_Click(object sender EventArgs e)
        {
            MessageBox.Show(“与创建窗体线程互不干扰“);
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     56320  2019-01-21 01:22  ThreadForm\.vs\ThreadForm\v14\.suo

     文件        189  2019-01-20 12:51  ThreadForm\ThreadForm\App.config

     文件       9216  2019-01-21 01:20  ThreadForm\ThreadForm\bin\Debug\ThreadForm.exe

     文件        189  2019-01-20 12:51  ThreadForm\ThreadForm\bin\Debug\ThreadForm.exe.config

     文件      22016  2019-01-21 01:20  ThreadForm\ThreadForm\bin\Debug\ThreadForm.pdb

     文件      22696  2019-01-21 01:22  ThreadForm\ThreadForm\bin\Debug\ThreadForm.vshost.exe

     文件        189  2019-01-20 12:51  ThreadForm\ThreadForm\bin\Debug\ThreadForm.vshost.exe.config

     文件        490  2015-07-10 19:01  ThreadForm\ThreadForm\bin\Debug\ThreadForm.vshost.exe.manifest

     文件       1962  2019-01-21 01:20  ThreadForm\ThreadForm\Form1.cs

     文件       3244  2019-01-21 01:03  ThreadForm\ThreadForm\Form1.Designer.cs

     文件       5817  2019-01-21 01:03  ThreadForm\ThreadForm\Form1.resx

     文件       1464  2019-01-20 20:53  ThreadForm\ThreadForm\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7240  2019-01-20 14:24  ThreadForm\ThreadForm\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2019-01-20 12:52  ThreadForm\ThreadForm\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2019-01-20 12:52  ThreadForm\ThreadForm\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2019-01-20 12:52  ThreadForm\ThreadForm\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件       1875  2019-01-21 01:22  ThreadForm\ThreadForm\obj\Debug\ThreadForm.csproj.FileListAbsolute.txt

     文件       1012  2019-01-21 01:03  ThreadForm\ThreadForm\obj\Debug\ThreadForm.csproj.GenerateResource.Cache

     文件       2384  2019-01-21 01:20  ThreadForm\ThreadForm\obj\Debug\ThreadForm.csprojResolveAssemblyReference.cache

     文件       9216  2019-01-21 01:20  ThreadForm\ThreadForm\obj\Debug\ThreadForm.exe

     文件        180  2019-01-21 01:03  ThreadForm\ThreadForm\obj\Debug\ThreadForm.Form1.resources

     文件      22016  2019-01-21 01:20  ThreadForm\ThreadForm\obj\Debug\ThreadForm.pdb

     文件        180  2019-01-20 23:14  ThreadForm\ThreadForm\obj\Debug\ThreadForm.Properties.Resources.resources

     文件        522  2019-01-20 12:51  ThreadForm\ThreadForm\Program.cs

     文件       1328  2019-01-20 12:51  ThreadForm\ThreadForm\Properties\AssemblyInfo.cs

     文件       2833  2019-01-20 12:51  ThreadForm\ThreadForm\Properties\Resources.Designer.cs

     文件       5612  2019-01-20 12:51  ThreadForm\ThreadForm\Properties\Resources.resx

     文件       1097  2019-01-20 12:51  ThreadForm\ThreadForm\Properties\Settings.Designer.cs

     文件        249  2019-01-20 12:51  ThreadForm\ThreadForm\Properties\Settings.settings

     文件       3918  2019-01-20 12:52  ThreadForm\ThreadForm\ThreadForm.csproj

............此处省略15个文件信息

评论

共有 条评论