【问题标题】:Loading a form in another Thread in .Net 2.0?在.Net 2.0 的另一个线程中加载表单?
【发布时间】:2011-07-18 12:04:42
【问题描述】:

所以,我有这个简单的控制台应用程序:

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using FormLoader;

namespace FormLoaderTest
{
    class Program
    {
        static void Main(string[] args)
        {
            FormLoaderClass.Load();

            while (true)
            {
                Console.Write(".");
                Thread.Sleep(17);
            }
        }
    }
}

这是 FormLoaderClass 类:

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;

namespace FormLoader
{
    public class FormLoaderClass
    {
        public void Load()
        {
            new ModLoaderWindow().Show();
        }
    }
}

第二个项目是从控制台应用程序引用的另一个 DLL。我的问题是表单显示但冻结,而控制台应用程序正在愉快地将点写入控制台窗口。

我该怎么做才能使控制台窗口继续写点,并且仍然可以与表单进行用户交互?我正在考虑一些线程,但这并没有真正起到作用。它要么只在第一次绘制时显示表格,要么一直冻结。

【问题讨论】:

    标签: c# winforms multithreading forms


    【解决方案1】:

    它冻结是因为表单需要一个消息队列——这就是Application.Run(Form f) 的用途。但是,该调用是阻塞的,因此您肯定需要第二个线程来运行它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-16
      • 1970-01-01
      • 2012-04-08
      相关资源
      最近更新 更多