一: 如果要在Ui线程中开启死循环会怎么样?
在ui线程中开启死循环后会使winform窗体无法移动。
二 : 代码
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
while (true)
{
System.Console.WriteLine("我是UI线程!");
}
}
}
}
三 如何解决?
开线程
四 解决问题的代码
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.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Thread MyThread = new Thread(() =>
{
while (true)
{
System.Console.WriteLine("我是UI线程!");
}
});
MyThread.Start();
}
}
}
五 效果
六: 如何在 winform程序里调用控制台程序?
在vs2013 里设置,如下图