public HttpContext context
{
get { return HttpContext.Current; }
set { value = context; }
}
然后建立一个委托
public delegate string delegategetResult(HttpContext context);
下面就是实现过程的编码
protected void Page_Load(object sender, EventArgs e)
{
context = HttpContext.Current;
delegategetResult dgt = testAsync;
IAsyncResult iar = dgt.BeginInvoke(context, null, null);
string result = dgt.EndInvoke(iar);
Response.Write(result);
} public static string testAsync(HttpContext context)
{
if (context.Application["boolTTS"] == null)
{
Hashtable ht = (Hashtable)context.Application["TTS"];
if (ht == null)
{
ht = new Hashtable();
} if (ht["A"] == null)
{
ht.Add("A", "A");
} if (ht["B"] == null)
{
ht.Add("B", "B");
} context.Application["TTS"] = ht;
} Hashtable hts = new Hashtable();
hts = (Hashtable)context.Application["TTS"];
if (hts["A"] != null)
{
return "恭喜,中大奖呀";
}
else
{
return "我猜你快中奖了";
}
}
本文异步 HttpContext.Current实现取值的方法(解决异步Application,Session,Cache...等失效的问题)到此结束。只有使自己自卑的心灵自信起来,弯曲的身躯才能挺直;只有使自己懦弱的体魄健壮起来,束缚的脚步才能迈开;只有使自己狭隘的心胸开阔起来,短视的眼光才能放远;只有使自己愚昧的头脑聪明起来,愚昧的幻想才能抛弃!小编再次感谢大家对我们的支持!