I would suggest you use a separate thread to do the job
解决方案 »
- 想请教一个问题,在线等
- 取回插入记录后的id
- 如何提升ASP.NET首页加载速度,减少服务器负载
- .net , sqlserver, mysql
- 母版页如何 引用内容页上的html控件值
- 字符串<td height="164">用引号括起来赋值给str1这个表达式应该如何写啊?
- 关于ActiveX,请高手指点.缘分那,谢谢啊.
- 怎样在返回按钮的相应事件中实现浏览器后退按钮的效果??
- 求救:为什么?这是为什么啊????????不明白啊,一会能用,一会又不能用?!!!关于前台控件绑定后台字符串的问题,前几天这么用还行来,今天就咋都不行了!!!
- 数据库存储过程的问题~~~~
- 也许是很简单的问题,来拿分呀!
- DataGrid问题
Threading in .NET Part 1
http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=296code:using System;
using System.Threading; public class my3Methods { public void myMethod1() {
Console.WriteLine("...myThread1 created!");
Thread.Sleep(5000);
Console.WriteLine("...myThread1 has finished!");
} public void myMethod2() {
Console.WriteLine("...myThread2 created!");
Thread.Sleep(3000);
Console.WriteLine("...myThread2 has finished!");
} public void myMethod3() {
Console.WriteLine("...myThread3 created!");
Thread.Sleep(1000);
Console.WriteLine("...myThread3 has finished!");
}
} public class ThreadTest { public static int Main(String[] args) { my3Methods testClass = new my3Methods(); Thread myThread1 = new Thread(new ThreadStart(testClass.myMethod1));
myThread1.Start(); Thread myThread2 = new Thread(new ThreadStart(testClass.myMethod2));
myThread2.Start(); Thread myThread3 = new Thread(new ThreadStart(testClass.myMethod3));
myThread3.Start(); return 0;
}
}
using System;
using System.Threading;public class TestCalc
{
System.Web.SessionState.HttpSessionState m_oSession;
public TestCalc(System.Web.SessionState.HttpSessionState s)
{
m_oSession = s;
} public void Calc()
{
long nCount = 0;
for (int i=0; i < 10000; i++)
{
Thread.Sleep(5);
nCount++;
} m_oSession["done"] = true;
}}
CalTest.aspx:<%@ Assembly Name="TestCalc" %>
<%@ Import Namespace="System.Threading" %>
<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e)
{
DisplayInfo();
}void RunCal(Object sender, EventArgs e)
{
Session["done"] = false;
Session["startTime"] = DateTime.Now; TestCalc c = new TestCalc(Session);
Thread myThread = new Thread(new ThreadStart(c.Calc));
myThread.Start(); DisplayInfo();
}void DisplayInfo()
{
if (Session["done"] != null)
{
if ((bool)Session["done"])
{
TimeSpan ts = DateTime.Now - (DateTime)Session["startTime"];
label1.Text = "done! total time: " + ts.TotalSeconds.ToString("F2") + " seconds";
}
else
{
btn.Visible = false; TimeSpan ts = DateTime.Now - (DateTime)Session["startTime"];
label1.Text = "still calculating...have been waiting for " + ts.TotalSeconds.ToString("F2") + " seconds"; Response.AddHeader("REFRESH","5");
}
}
}
</script>
<form runat="server">
<asp:button id="btn" text="run" runat="server" onclick="RunCal"/>
<asp:label id="label1" runat="server" />
</form>
还有问题问saucer高手,同一问题,Response.AddHeader("REFRESH","5")是每隔五秒刷一次,可是也将我原网页上的配置给全刷新了,如:有两个下拉控件选中的内容全给刷新为初始值了,如何控制??在线等候!!
Response.AddHeader("REFRESH","5");you might want to add a client side script, like
<script language='javascript'>function window.onload(){setTimeout('form1.submit()',5000);}</script>
use a session variable, inside the other thread, periodically update its valuein your page, check this session variable's value>>>5000是超时的秒吗
yes
1:线程中的Session变化了,无法在Page中及时反映出来。
2:如何编制循环监控程序(C#)。
3:Page 不刷新,可能有会出现我最初问的页面出错的老问题,特别是针对大文件!
切盼帮助!