|
復(fù)制代碼 代碼如下:
public HttpContext context
{
get { return HttpContext.Current; }
set { value = context; }
}
然后建立一個(gè)委托
復(fù)制代碼 代碼如下:
public delegate string delegategetResult(HttpContext context);
下面就是實(shí)現(xiàn)過(guò)程的編碼
復(fù)制代碼 代碼如下:
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 "恭喜,中大獎(jiǎng)呀";
}
else
{
return "我猜你快中獎(jiǎng)了";
}
}
AspNet技術(shù):異步 HttpContext.Current實(shí)現(xiàn)取值的方法(解決異步Application,Session,Cache...等失效的問(wèn)題),轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。