Taskが別スレッドで動作するのはご存知と思います。
別スレッドで動作するということは、Mainスレッドをブロックしないということです。
Mainメソッドが終了すると、Mainスレッドが終了し、アプリケーションが終了してしまいます。
Task.Waitメソッドなどでタスクの終了を待機してください。
C#
1var runningTask = new List<Task>();
2
3for (int i = 0; i < 2; i++)
4{
5 runningTask.Add(Task.Run(() =>
6 {
7 Application.Run(new Form1("Hello World!! "));
8 }));
9}
10
11foreach(Task t in runningTask)
12{
13 t.Wait();
14}
追記
C#
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4using System.Windows.Forms;
5
6namespace Test
7{
8 class Form1 : Form
9 {
10 static void Main(string[] args)
11 {
12
13 var runningTask = new List<Task>();
14
15 foreach(string arg in args)
16 {
17 runningTask.Add(Task.Run(() =>
18 {
19 Application.Run(new Form1(arg));
20 }));
21 }
22
23 foreach(var t in runningTask)
24 {
25 t.Wait();
26 }
27 }
28
29 private TextBox textBox1;
30
31 public Form1(string file)
32 {
33 this.textBox1 = new System.Windows.Forms.TextBox();
34 this.textBox1.Location = new System.Drawing.Point(10, 10);
35 this.textBox1.Size = new System.Drawing.Size(150, 20);
36 this.textBox1.Text = file;
37
38 this.ClientSize = new System.Drawing.Size(200, 50);
39 this.Controls.Add(this.textBox1);
40 }
41 }
42}
43
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/05/30 08:49
2016/05/31 02:11