c#多线程刷新界面
这个问题也不知道难倒了多少C#豪杰。比起MFC的界面刷新,在WINFORM中来实现多线程刷新真是很痛苦,故写此文。
多线程刷新界面主要用到多线程,委托,线程安全、事件等一系列高难度的C#操作。
关于委托和事件,这有一篇很易懂的文章:hi.baidu.com/anglecloudy/blog/item/a52253ee804d052f2df534ab.html
===============================================
先从一个简单的例子说起,是一个没有考虑线程安全的写法:
先在一个FORM类里面定义一个委托和事件:
protected delegate void UpdateControlText1(string str);
//定义更新控件的方法
protected void updateControlText(string str)
{
this.lbStatus.Text = str ;
return;
}
在线程函数里面加上下面的内容
UpdateControlText1 update = new
UpdateControlText1(updateControlText);//定义委托
this.Invoke(update,
"OK");//调用窗体Invoke方法
这个线程函数必须是类的线程函数,这样用很方便,但有很高的局限性,下面来说个复杂的。
==============================================
先定义一个独立的类
public
class
MoreTime
{
public
delegate
void
InvokeOtherThead(
int
i);//委托
public
InvokeOtherThead MainThread;//事件
public
void
WaitMoreTime()
{
for
(
int
i
=
0
; i
<
20
;i
++
)
{
&n
相关文档:
[System.Runtime.Serialization.DataMemberAttribute()]
public Information Archive {
get {
&n ......
在root账号中,可以正常调用存储过程.
换到common_user账号时,同一存储过程名调用出现问题.
追踪调试时出现:
SELECT command denied to user 'common_user'@'localhost' for table 'proc'
搜索解决方案:
MySqlConnection myconnection = new MySqlConnection("server=localhost;user id=common_user; password=***;dat ......
public partial class shujuku_huanyuan : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection(@"server=HUAZD-33\XXD33;uid=sa;pwd=111111;database=master;");
protected void Page_Load(object sender, EventArgs e)
&nbs ......
新建一个专门用来创建验证码图片的页面ValidateCode.aspx
它的后台cs文件代码如下:
PageLoad
private void Page_Load(object sender, System.EventArgs e)
{
string checkCode = CreateRandomCode(4);
Session["CheckCode"] = checkCode;
CreateImage(checkCode);
......
//以下来自:http://msdn.microsoft.com/zh-cn/library/sf985hc5.aspx
abstract(C# 参考)
更新:2007 年 11 月
abstract 修饰符可以和类、方法、属性、索引器及事件一起使用。在类声明中使用 abstract 修饰符以指示某个类只能是其他类的基类。标记为抽象或包含在抽象类中的成员必须通过从抽象类派生的类来实现。
示例 ......