using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Threading; using ZhongHeMgmt.DBUtility; using ZhongHeMgmt.Utility; using System.Runtime.InteropServices; using System.Text; using System.Data.SqlClient; using System.IO;public partial class Webs_deal_with_phone_iframe : System.Web.UI.Page { private static ZhongHeMgmt.DBUtility.DataBase db = new DataBase(); private static string str_SQL = ""; public string str_Sound_Table = ""; public int getcurrentint = 0; Thread td_main; protected void Page_Load(object sender, EventArgs e) { td_main = new Thread(main); } private void main() { while (Session["ready"].ToString() == "0") { Thread.Sleep(1000); str_SQL = "insert into t_msg_log (port) select 1"; db.RunExecuteNonQuery(str_SQL); } } } 这个是测试程序
2.Application.ExitThread();
3.遍历活动线程,挨个结束
System.Threading.Thread.CurrentThread.Abort();
或者 Process.GetCurrentProcess().Kill()
Application.ExitThread()是winform中的
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Threading;
using ZhongHeMgmt.DBUtility;
using ZhongHeMgmt.Utility;
using System.Runtime.InteropServices;
using System.Text;
using System.Data.SqlClient;
using System.IO;public partial class Webs_deal_with_phone_iframe : System.Web.UI.Page
{
private static ZhongHeMgmt.DBUtility.DataBase db = new DataBase();
private static string str_SQL = "";
public string str_Sound_Table = "";
public int getcurrentint = 0;
Thread td_main;
protected void Page_Load(object sender, EventArgs e)
{
td_main = new Thread(main);
}
private void main()
{
while (Session["ready"].ToString() == "0")
{ Thread.Sleep(1000);
str_SQL = "insert into t_msg_log (port) select 1";
db.RunExecuteNonQuery(str_SQL);
}
}
}
这个是测试程序
这个是关闭的事件
之所以定位B/S、C/S,无非是因为它们各有所长,按需选择。不然还有必要分吗?
记得<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Async="true" %>
不然别用Thread,因为你无法跟踪它们,有异常它们不会自动关闭,除非关闭应用程序池
推荐ThreadPool+WebService
程序里有一个函数是专门到数据库里取没有发送数据的,未发送的数据是别的程序产生的在不断的递增,如果不使用while(true)就没法领到最新的未处理数据,自动处理也就无从谈起了,使用了while(ture)不用多线程页面根本不能显示出来