首页 新闻 会员 周边

asp.net 加入线程池页面无法跳转~~~~~急

0
悬赏园豆:50 [已关闭问题] 关闭于 2010-06-21 17:05

 

1 namespace WebApplication4
2 {
3 public partial class _Default : System.Web.UI.Page
4 {
5 int num = 3;
6 public static Object obj = new object();
7 static int sum = 0;
8 protected void Page_Load(object sender, EventArgs e)
9 {
10
11 }
12
13 protected void Button1_Click(object sender, EventArgs e)
14 {
15
16 WaitCallback callback = new WaitCallback(Msg);
17 ThreadPool.SetMaxThreads(num, num);
18 //线程池
19   for (int i = 0; i < num; i++)
20 {
21 ThreadPool.QueueUserWorkItem(callback);
22 }
23 //等待线程执行完成以后再往下执行
24   while (true)
25 {
26 if (sum == num)
27 {
28 Response.Write(sum);
29 break;
30 }
31 }
32
33 Response.Write("<script>alert('Success')</script>");
34 Response.Redirect("WebForm1.aspx");
35 //Redirect();
36  
37 }
38
39 public void Msg(Object State)
40 {
41 lock (obj)
42 {
43 sum++;
44 }
45 }
46
47 }
48 }

 

我在页面中加入了一个线程池.结果在第34行跳转页面的时候却无法跳转,希望各位大虾又碰到过这个问题的说一下,小弟在这先谢谢啦

问题补充: While里面的循环回结束,而且调试的时候,第34行是会执行的,但是执行完以后页面没有跳转. 多谢Ou lei,Try..Catch提示"线程被中止",这个有什么解决的方法吗?
槑槑的主页 槑槑 | 初学一级 | 园豆:105
提问于:2010-06-21 10:25
< >
分享
所有回答(1)
0

如果代码真的执行了,页面肯定会跳转,问题是代码真的被执行了?

 

try
{
}
catch (System.Threading.ThreadAbortException)
{
}

 

try一下吧

Response.Redirect("WebForm1.aspx",false);
Ou lei | 园豆:619 (小虾三级) | 2010-06-21 11:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册