ASP.NET C# B⼀S结构 我想实现一个线程监控
我想实现一个简单的线程监控,就是客户端登陆的时候,我吧他的登陆时间记录在数据库,离开的时候(直接关闭页面,或者断电)我记录它的离开时间!我不知道怎么写?从网上看了下 捣鼓了一点点,不知道对不对,而且不知道怎么写下去了,希望大家能帮个忙个修改并完善下,谢谢了!using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Net;using System.Net.Sockets;using System.IO;using JH.Game.ServiceLibrary.Model;using JH.Game.ServiceLibrary.Bll;using FluorineFx.Data;using FluorineFx;using FluorineFx.AMF3;namespace JH.Game.ServiceLibrary.RemotingService{ [RemotingService] public class listener { public listener() { } //IP地址 private IPAddress ip; //端口 private int port; //监听器 private TcpListener Tcls = null; //监听线程 private Thread th; //启动线程 private void Start() { th = new Thread(new ThreadStart(Func)); th.IsBackground=true; th.Start(); } //停止线程 private void Stop() { th.Abort(); if (Tcls != null) { Tcls.Stop(); Tcls = null; } } private void Func() { Tcls = new TcpListener(ip,port); Tcls.Start(); while (true) { if (Tcls.Pending()) { TcpClient tc = Tcls.AcceptTcpClient(); Client cl = new Client(tc, th); th.Start(cl); } else { Thread.Sleep(300); } } }可以加分的!