我有一个程序,要重复不断的用GDI+画图,而且在画图的过程要执行很多函数。
是这样的,画图我在panel1_Paint()事件中写入画图代码(里面有函数,图像随时改变),
然后用this.panel1.Invalidate();实现图像变化。
我在窗体中加入一个按钮,点击按钮的时候开始画图,并且执行很多函数,这样图像不会显示。
我想加入一个线程,把一些函数都放到线程中执行。
比如,我想实现如下操作的同时画图。
while(表达式)
{
函数1();
函数2();
函数3();
this.panel1.Invalidate();//函数x();对图像有影响。
}
while是在button按钮事件中。
其中 函数x();都是对数组的操作。
如何使用线程把这个while表达式中的函数包裹起来在后台运行??
如果不用线程,可有其他方法???
是这样的,画图我在panel1_Paint()事件中写入画图代码(里面有函数,图像随时改变),
然后用this.panel1.Invalidate();实现图像变化。
我在窗体中加入一个按钮,点击按钮的时候开始画图,并且执行很多函数,这样图像不会显示。
我想加入一个线程,把一些函数都放到线程中执行。
比如,我想实现如下操作的同时画图。
while(表达式)
{
函数1();
函数2();
函数3();
this.panel1.Invalidate();//函数x();对图像有影响。
}
while是在button按钮事件中。
其中 函数x();都是对数组的操作。
如何使用线程把这个while表达式中的函数包裹起来在后台运行??
如果不用线程,可有其他方法???
解决方案 »
- C#如何实现js的时间戳-Date.parse(new Date())
- winfom问题
- C# 怎么用up键代替shift+tab,大家帮帮忙!谢谢……
- 做一个像 windows 开始按钮一样的一个Button
- 往这个javascript:display(变量)里面动态产生值有可能吗??
- 请求会C#和oracle技术的达人诊断诊断merge into的问题
- 判断字符串是否有连续的两个英文句点(.)求最佳算法
- SQL server 数据库备份问题
- 根据条件自动关机的代码问题
- 急聘,软件工程师(WEB相关),打扰了。(
- C#如何读写WINCE。NET的注册表
- 急。。。。有哪位朋友写过和扫描仪连接的东西没 ?能不能给个例子看看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace WindowsApplication2
{
public partial class Form1 : Form
{
private Thread _thread = null;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ThreadStart threadStart = new ThreadStart(threadStart);
_thread = new Thread(threadStart);
_thread.Start();
}
public void ThreadMothed()
{
try
{
X1();
X2();
}
catch (ThreadAbortException ex)
{
Thread.ResetAbort(); }
}
public void X1()
{
}
public void X2()
{
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace WindowsApplication2
{
public partial class Form1 : Form
{
private Thread _thread = null;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ThreadStart threadStart = new ThreadStart(ThreadMothed); //这个地方应该些对应的方法
_thread = new Thread(threadStart);
_thread.Start();
}
public void ThreadMothed()
{
try
{
X1();
X2();
}
catch (ThreadAbortException ex)
{
Thread.ResetAbort(); }
}
public void X1()
{
}
public void X2()
{
}
}
}
// in your thread function
while(表达式)
{
函数1();
函数2();
函数3();
this.panel1.Invalidate();//函数x();对图像有影响。
Thread.Sleep( 20 );// Suspend current sub-thread
}