| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 530 人关注过本帖
标题:请教一个简单问题(多线程的)
只看楼主 加入收藏
yuerhb
Rank: 1
等 级:新手上路
威 望:1
帖 子:241
专家分:0
注 册:2007-6-1
收藏
 问题点数:0 回复次数:2 
请教一个简单问题(多线程的)
先说一下我的问题:主要就是想实现(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
半夜杀猪
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:12
专家分:114
注 册:2012-2-19
收藏
得分:0 
按钮里执行了一个线程,线程执行完毕就被系统回收了。线程就没了。

群:93467528,c# Net,要大侠不要菜鸟!不许广告,不乱聊,不问入门问题。
2012-06-20 15:39
快速回复:请教一个简单问题(多线程的)
数据加载中...
 
   



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

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