C# 如何使用在visual studio上运行两个进程

C# 如何使用在visual studio上运行两个进程,c#,visual-studio,C#,Visual Studio,我正在用XNA编写一个游戏,我有一个登录屏幕,它是windows窗体,还有游戏本身。我需要从登录屏幕转到游戏,但当我尝试时,它会说我一次不能运行超过一个thred。我怎样才能解决这个问题? 这是登录屏幕代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using Sy

我正在用XNA编写一个游戏,我有一个登录屏幕,它是windows窗体,还有游戏本身。我需要从登录屏幕转到游戏,但当我尝试时,它会说我一次不能运行超过一个thred。我怎样才能解决这个问题? 这是登录屏幕代码:

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

namespace ProtoType
{
    public partial class SighIn : Form
    {
        public SighIn()
     {
        InitializeComponent();

     }

    private void button1_Click(object sender, EventArgs e)
    {
        if ((textBox1.Text.Equals("Developer")) && (textBox2.Text.Equals("poxus17")))
        {
            using (Game1 game = new Game1())
            {                  
                game.Run();
            }

        }
    }
  }
}

XNA Game.Run方法执行Application.Run,它为主线程(UI线程)提供消息泵

在窗体运行并单击按钮时,Application.Run已在执行(可能通过form.ShowDialog)。同一线程中不能同时有两个消息泵

解决方案是允许Application.Run完成,然后调用Game.Run

大概是这样的:

Form form = new SignIn();
if (form.ShowDialog() == DialogResult.OK)
{
    if (form.UserName =="Developer" && form.Password == "poxus17")
    {
        using (Game1 game = new Game1())
        {
            game.Run();
        }
    }
}

现在,表单的按钮单击处理程序可以将文本框字段复制到属性(用户名和密码)并设置为。DialogResult=DialogResult.OK。这将关闭表单,完成ShowDialog启动的消息泵,然后在验证后,使用Game.Run启动一个新的消息泵。

命名空间系统。线程化是一个很好的开始。恐怕它不起作用。如果不清楚,我使用application.run来激活程序,而不是showDialog(),因为这会导致问题。@user3439131是否替换了program.Main(或Main所在的位置)的内容?