以下将展示窗体调用部的代码,窗体中新建了一个按钮,使用按钮的 Click 事件执行并行程序,代码如下:
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;
首先贴出控制台执行程序,验证该代码是正确的。代码具体如下:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Test
{
class A
{
public String strName;
public A( String str )
{
this.strName = str;
}
public void printMessage()
{
System.DateTime dt = System.DateTime.Now;
for( int i = 0; i < 50000; i++ )
{
Console.WriteLine( "当前时间 " + String.Format( "{0:yyyy-MM-dd HH::mm::ss::ffff}",dt ) + " " +
" i = " + i + " " + this.strName ); // 注意时间的格式化;
}
}
}
class Program
{
static void Main( string[] args )
{
A a1 = new A( "11111" );
A a2 = new A( "22222" );
A a3 = new A( "33333" );
A a4 = new A( "44444" );