首页 新闻 搜索 专区 学院

球高手指点

0
悬赏园豆:10 [待解决问题]

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.Threading;


namespace WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
       
      

        //private const int numIterations = 1;
        //private const int numThreads = 3;
       
        public static Point p1 = new Point(199, 53), p2 = new Point(199, 119), p3 = new Point(388,32);
        public static Button[] btn = new Button[3];
        //public string n = "green";
        public Form1()
        {
            InitializeComponent();
        }
        public static void movein(int from, int target)
        {
            string ms =  from.ToString() + "进到" + target.ToString() + "厕所里去;";
            MessageBox.Show(ms);
            //string n = "red";
            Point pt=new Point();
            pt.X = 388;
            pt.Y = 32;
         
        }

        public static void moveout(int from, int target)
        {
            string ms = from.ToString() + "离开" + target.ToString() + "厕所;";
            MessageBox.Show(ms);
            Point pt = new Point();
            pt.X = 199;
            pt.Y = 80;
        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void 厕所_Click(object sender, EventArgs e)
        {

        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {

        }
        public class Test : Form1
        {
            private static Mutex textbook1 = new Mutex();
            private const int numIterations = 1;
            private const int numThreads = 2;

            static void Main()
            {
                // Create the threads that will use the protected resource.
                for (int i = 0; i < numThreads; i++)
                {
                    Thread myThread = new Thread(new ThreadStart(MyThreadProc));
                    myThread.Name = String.Format("Thread{0}", i + 1);
                    myThread.Start();

                }

                // The main thread exits, but the application continues to
                // run until all foreground threads have exited.
            }

            private static void MyThreadProc()
            {
                for (int i = 0; i < numIterations; i++)
                {
                    UseResource();
                }
            }

            // This method represents a resource that must be synchronized
            // so that only one thread at a time can enter.
            private static void UseResource()
            {
                // Wait until it is safe to enter.
                mut.WaitOne();

                Console.WriteLine("{0} has entered the protected area",
                    Thread.CurrentThread.Name);

                // Place code to access non-reentrant resources here.

                // Simulate some work.
                Thread.Sleep(500);

                Console.WriteLine("{0} is leaving the protected area\r\n",
                    Thread.CurrentThread.Name);

                // Release the Mutex.
                mut.ReleaseMutex();
            }
        }
    }
}

错误 1 当前上下文中不存在名称“mut”

错误 2 当前上下文中不存在名称“mut”   

目的是用 c# 的 winform 写个用图形界面 表示互斥 的程序 新手刚学c# 不知怎么改

yazi55的主页 yazi55 | 初学一级 | 园豆:190
提问于:2010-11-27 21:45
< >
分享
所有回答(2)
0

你把textbook1改为mut试试

artwl | 园豆:16536 (专家六级) | 2010-11-28 07:30
0

mut你都没定义,确实新嫩啊

茂茂 | 园豆:2860 (老鸟四级) | 2010-11-29 09:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册