会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
李占卫的网上家园
博客园
首页
新随笔
联系
订阅
管理
多线程,委托例子
多线程:
Type text here
class
ActiveDate
{
private
string
_CusID;
private
string
_Visitor;
private
int
_ShopNum;
private
int
_flag
=
0
;
public
int
Flag
{
get
{
return
_flag; }
set
{ _flag
=
value; }
}
public
string
CusID
{
get
{
return
_CusID; }
set
{ _CusID
=
value; }
}
public
string
Visitor
{
get
{
return
_Visitor; }
set
{ _Visitor
=
value; }
}
public
int
ShopNum
{
get
{
return
_ShopNum; }
set
{ _ShopNum
=
value; }
}
public
void
GetCustomerVisitor()
{
_Visitor
=
DAL.CRM.Common.Customer.GetCustomerVisitor(_CusID);
lock
(
this
)
{
_flag
++
;
}
}
public
void
GetCustomerShopNums()
{
_ShopNum
=
Convert.ToInt32(DAL.CRM.Common.Customer.GetCustomerShopNum(_CusID));
lock
(
this
)
{
_flag
++
;
}
}
}
Module.CRM.Customer.CustomerActiveDate date
=
new
Module.CRM.Customer.CustomerActiveDate();
ActiveDate ad
=
new
ActiveDate();
ad.CusID
=
customerID;
Thread tr1
=
new
Thread(
new
ThreadStart(ad.GetCustomerVisitor));
Thread tr2
=
new
Thread(
new
ThreadStart(ad.GetCustomerShopNums));
tr1.Start();
tr2.Start();
while
(
true
)
{
if
(ad.Flag
==
2
)
{
date.Visitor
=
ad.Visitor;
date.ShopNum
=
ad.ShopNum;
tr1.Abort();
tr2.Abort();
return
date;
}
}
委托:
delegate
string
myDelegate(String Name);
myDelegate d1
=
new
myDelegate(DAL.CRM.Common.Customer.GetCustomerVisitor);
myDelegate d2
=
new
myDelegate(DAL.CRM.Common.Customer.GetCustomerShopNum);
IAsyncResult i1
=
d1.BeginInvoke(customerID,
null
,
null
);
Module.CRM.Customer.CustomerActiveDate date
=
new
Module.CRM.Customer.CustomerActiveDate();
IAsyncResult i2
=
d2.BeginInvoke(customerID,
null
,
null
);
bool
_flag
=
false
;
while
(
!
_flag)
{
_flag
=
i1.IsCompleted
&&
i2.IsCompleted;
}
date.Visitor
=
d1.EndInvoke(i1);
date.ShopNum
=
Convert.ToInt32(d2.EndInvoke(i2));
return
date;
posted @
2007-10-12 17:46
李占卫
阅读(
494
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告