有空帮我看一下,多线程(问题:从不同步的代码块中调用了对象同步方法)

本文通过一个Windows应用程序示例,展示了如何在多线程环境中处理对象同步问题。当按钮被点击时,启动两个线程,一个负责增加数值并更新文本框,另一个负责读取数值并显示。使用Monitor类进行线程同步,确保在特定条件下对共享资源的访问是互斥的,并通过 Pulse 和 Wait 方法控制线程执行流程。
摘要由CSDN通过智能技术生成

using System;
using System.Threading;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

 

namespace WindowsApplication6_线程同步
{
    public partial class Form1 : Form
    {
        //Forms.Control.CheckForIllegalCrossThreadCalls   =   false;
        public Int64 number;
        Thread thread1;
        Thread thread2;
        public bool fSync = false;
        public common oCommon;
        AddNumberClass addclass;
        ReadNumber readclass;
        public Form1()
        {
            InitializeComponent();
            oCommon = new common();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        Control.CheckForIllegalCrossThreadCalls   =   false;

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值