|
復制代碼 代碼如下:
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 "我猜你快中獎了";
}
}
AspNet技術:異步 HttpContext.Current實現取值的方法(解決異步Application,Session,Cache...等失效的問題),轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。