十万火急 !!!!!asp.net中的Application类型转换
我在Global的Application_Start中将Application[ "UserTotal "]初始化为0,
Application[ "UserTotal "] = 0;
在Session_Start事件中添加如下代码,将Application[ "UserTotal "]强制类型转换为uint型,可是运行的时候不太稳定,有的时候可以正常运行,有的时候会报错,显示类型转换错误。该怎样解决??
Application.Lock();
//数值累加,注意这里使用了装箱(boxing)
uint uiCountNum = 0;
uiCountNum = (uint)Application[ "UserTotal "];
uiCountNum = uiCountNum + 1;
object obj = uiCountNum;
Application[ "UserTotal "] = obj;
------解决方案--------------------int i ;
if(Application[ "UserTotal "] == null)
i =1;
else
i = (int)Application[ "UserTotal "] +1;
Application.Lock();
Application[ "UserTotal "] = i;
Application.UnLock();
------解决方案--------------------int i =0;
if(Application[ "UserTotal "] != null)
int.TryParase(Application[ "UserTotal "].ToString(),out i);
i++;
Application.Lock();
Application[ "UserTotal "] = i;
Application.UnLock();
------解决方案--------------------你是要做网站统计人数吧,可以把这个值放到数据库里面呀,这样应该就不会有事了