小弟我刚开始学线程,现在已到了点麻烦,希望路过的大侠能帮帮忙,最好能给出改进后的解决办法,小弟我感激不尽!
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 线程练习
{
public partial class Form1 : Form
{
private Thread th;
//public static bool CheckForIllegalCrossThreadCalls = false;
public Form1()
{
InitializeComponent();
}
int x = 10, y = 100;
public void go()
{
while (true)
{
x += 10;
y += 10;
Thread.Sleep(1000);
// Refresh();
}
}
private void button1_Click(object sender, EventArgs e)
{
th = new Thread(new ThreadStart(go));
th.Start();
} private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.FillRectangle(Brushes.Red, x, y, 10, 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 线程练习
{
public partial class Form1 : Form
{
private Thread th;
//public static bool CheckForIllegalCrossThreadCalls = false;
public Form1()
{
InitializeComponent();
}
int x = 10, y = 100;
public void go()
{
while (true)
{
x += 10;
y += 10;
Thread.Sleep(1000);
// Refresh();
}
}
private void button1_Click(object sender, EventArgs e)
{
th = new Thread(new ThreadStart(go));
th.Start();
} private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.FillRectangle(Brushes.Red, x, y, 10, 10);
}
}
}
解决方案 »
- wpf datagrid 问题
- 添加了信息后子窗体就关闭 但是父窗体的gridview没有刷新
- 控件绑定到数据后,间歇性异常
- 垃圾收集器
- Access中OLE对象存储图片时,要把图片转换成什么类型呢?(越快越好)
- C# for windows 中,怎样批量录入数据?
- 接着散分,都是很简单的问题,怎样格式化时间显示到分例如2005/5/10 10:30
- 微信公众平台上服务器配置中的token可以用代码获取吗??
- 還是請C#(懂vb)高手回答
- 请问Wise For Visual Studio.Net是什么?
- 同一个私有IP域下的两个局域网通信 求解啊求解
- C# winform DataGridview相关问题
{
......;
});
CheckForIllegalCrossThreadCalls = false;但是不推荐这么做 具体是为什么以及怎么做 请看链接
http://hi.baidu.com/yyq745201/blog/item/0156034b3a6b342e08f7ef36.html