编写一个多线程程序,同时启动2个线程,a线程打印1到100,b线程打印101到200
展开全部
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ConsoleApplication10
{
class Program
{
static void Main(string[] args)
{
Thread thread1 = new Thread(Print1_100);
Thread thread2 = new Thread(Print101_200);
thread1.Start();
thread2.Start();
Console.Read();
}
private static void Print1_100()
{
Print(1, 100);
}
private static void Print101_200()
{
Print(101, 200);
}
private static void Print(int min, int max)
{
for (int i = min; i <= max; i++)
{
Console.WriteLine(i);
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ConsoleApplication10
{
class Program
{
static void Main(string[] args)
{
Thread thread1 = new Thread(Print1_100);
Thread thread2 = new Thread(Print101_200);
thread1.Start();
thread2.Start();
Console.Read();
}
private static void Print1_100()
{
Print(1, 100);
}
private static void Print101_200()
{
Print(101, 200);
}
private static void Print(int min, int max)
{
for (int i = min; i <= max; i++)
{
Console.WriteLine(i);
}
}
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace BaiduZhidao
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnThread_Click(object sender, EventArgs e)
{
Thread th1 = new Thread(new ThreadStart(print1));
Thread th2 = new Thread(new ThreadStart(print2));
th1.Start();
th2.Start();
}
private void print1()
{
print(1, 100);
}
private void print2()
{
print(101, 200);
}
private void print(int begin, int end)
{
for (int i = begin; i <= end; i++)
{
Console.WriteLine(i);
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace BaiduZhidao
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnThread_Click(object sender, EventArgs e)
{
Thread th1 = new Thread(new ThreadStart(print1));
Thread th2 = new Thread(new ThreadStart(print2));
th1.Start();
th2.Start();
}
private void print1()
{
print(1, 100);
}
private void print2()
{
print(101, 200);
}
private void print(int begin, int end)
{
for (int i = begin; i <= end; i++)
{
Console.WriteLine(i);
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询