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行跳转页面的时候却无法跳转,希望各位大虾又碰到过这个问题的说一下,小弟在这先谢谢啦
如果代码真的执行了,页面肯定会跳转,问题是代码真的被执行了?
try
{
}catch (System.Threading.ThreadAbortException)
{
}
try一下吧
Response.Redirect("WebForm1.aspx",false);