开发者

Loading a form in another Thread in .Net 2.0?

开发者 https://www.devze.com 2023-02-17 23:21 出处:网络
So, I have this simple console application: using System; using System.Collections.Generic; using System.Text;

So, I have this simple console application:

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

This is the FormLoaderClass class:

using System;
using开发者_如何学C 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();
        }
    }
}

The second project is another DLL referenced from the Console application. My problem is that the form is shown but frozen, while the console application is happily writing dots to the console window.

What can I do so the console window will keep writing dots, and user interaction with the Form is still possible? I was thinking of some threading, but that didn't really did the trick. It either showed the form only the first time it was drawn, or it kept freezing.


It freezes because a Form needs a Message Queue - that's what Application.Run(Form f) is for. However, that call is blocking so you'll definitely need a second thread to run it.

0

精彩评论

暂无评论...
验证码 换一张
取 消