请举例 两个或更多的线程可能在同一时间访问相同的资源出错的例子
来源:百度知道 编辑:UC知道 时间:2024/05/29 23:31:13
建一个做一个windows应用程序,然后把form1文件的内容改为以下
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 WindowsApplication1
{
public partial class Form1 : Form
{
Thread t1;
Thread t2;
Bitmap b;
public Form1()
{
InitializeComponent();
b = new Bitmap(10, 10);
t1 = new Thread(new ThreadStart(aa));
t2 = new Thread(new ThreadStart(bb));
t1.Start();
t2.Start();
}
protected override void OnClosed(EventArgs e)
{
t1.Abort();
t2.Abort();
base.OnClosed(e);
}
void aa()
{