c# - 在新线程中启动表单并在它们之间引发事件

标签 c# .net multithreading winforms

我尝试在新线程中启动表单(请参阅下面的代码架构)。 但是表单在显示后关闭。

Thread te;    
dia di = new dia();
private static Thread te;
public static event AddingNewEventHandler tempchange;
public delegate void AddingNewEventHandler(int sender, EventArgs e);
static void Main(string[] args)
{    
   di.Coneig += new Config.AddingNewEventHandler(config);
   te = new Thread(new ThreadStart(di.Show));     
   te.Start();    
   while(true)
   {
     //async code to Form
   }
}

public static void config(int[] sender, EventArgs e)
{
    //Edit some values in the main(Class variables)
}

最佳答案

Thread te;    
dia di = new dia();

static void Main(string[] args)
{    
   te = new Thread(new ThreadStart(di.Show));     
   te.Start();    
   Console.ReadKey();
}

编辑:

这个作品我检查过..

    static void Main(string[] args)
    {
       Form di = new Form();


        Thread te = new Thread(() => 
        {
            Application.EnableVisualStyles();
            Application.Run(di);
        });
        te.Start();
    }

关于c# - 在新线程中启动表单并在它们之间引发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33952777/

相关文章:

.net - 为什么 BCL 没有 CRC 类?

C# 位图填充

c# - 我如何继承 WaitHandle?

c# - 将构造函数参数传递给根对象的依赖项,作为 Ninject 中单个解析的一部分

c# - 如何简化单元测试 DDD Value objects Equality with AutoFixture

c# - 在哪里存储数据以避免数据库命中?

c# - 在列表中使用 Linq 选择列表

java - 服务在线程中运行

c++ - 同步访问返回值

javascript - 没有从 SignalR 跨域返回任何消息,但 ping 正常