标题:请教一个简单问题(多线程的)
取消只看楼主
yuerhb
Rank: 1
等 级:新手上路
威 望:1
帖 子:241
专家分:0
注 册:2007-6-1
 问题点数:0 回复次数:1 
请教一个简单问题(多线程的)
先说一下我的问题:主要就是想实现(winform中)
1.在时钟里更新数组,
2.在一个线程中利用这个数组的值画出曲线。
下面是我写的程序,图就画了一次不知道怎么回事?请高手指教。。。。


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

namespace WindowsApplication3
{
    public partial class Form1 : Form
    {
        static  int[] a = new int[10];
        static int[] b = new int[10];
        static int count = 0;
        Object obj = new Object();//
        public Form1()
        {
            InitializeComponent();
        }
        private void draw()
        {
            Graphics g = pictureBox1.CreateGraphics();
            Pen pen1 = new Pen(Color.Red, 2);
            g.Clear(Color.White);
            lock (a)
            {
                for (int i = 0; i < 9; i++)
               g.DrawLine(pen1, a[i], b[i], a[i + 1], b[i + 1]);
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            lock (a)
            {
                    for (int i = 0; i < 10; i++)
                    {
                        a[i] = (50 + count * 10) * i;
                        if (i % 2 == 0) b[i] = 30;
                        else b[i] = 50;
                    }
                    if (count < 10) count++;
                    else count = 0;
            }
            
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 10; i++)
            {
                a[i] = 50 * i;
                if (i % 2 == 0)b[i] = 30;
                else b[i] = 50;
            }
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ThreadStart ts = new ThreadStart(draw);
            Thread thread = new Thread(ts);
            thread.Start();
            timer1.Enabled = true;
        }
    }
}
搜索更多相关主题的帖子: 曲线 public 多线程 
2012-06-17 23:25
yuerhb
Rank: 1
等 级:新手上路
威 望:1
帖 子:241
专家分:0
注 册:2007-6-1
得分:0 
来人啊

学编程。。。。再难也得上!!!
2012-06-18 08:16



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-371742-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.053219 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved