加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
LoanSvr.cs 3.48 KB
一键复制 编辑 原始数据 按行查看 历史
Uleen 提交于 2024-11-07 18:02 . update
using LJLib.TcpHandle;
using LoanSvr;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.ServiceProcess;
using System.Threading;
using LJLib.D;
using LJLib.DAL.SQL;
using LJLib.HttpServer;
using LJLib.Tools.File;
using LoanSvr.BLL;
namespace LoanSvr
{
partial class LoanSvr : ServiceBase
{
private TcpListener _tcpListener = null;
private static bool running = false;
public LoanSvr()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
try
{
DbSqlHelper.Add(new SqlServerEngine());
GlobalVar.webapp = false;
GlobalVar.Init();
XmlConfig xmlconfig = new XmlConfig();
var strport = xmlconfig.GetXmlFileValue(GlobalVar.XmlFile, string.Empty, "port", "9075");
var strHttpPort = xmlconfig.GetXmlFileValue(GlobalVar.XmlFile, string.Empty, "httpport", "9076");
int port = int.Parse(strport);
int httpport = int.Parse(strHttpPort);
startHttpListener(httpport);
_tcpListener = new TcpListener(IPAddress.Any, port);
_tcpListener.Start();
ThreadPool.QueueUserWorkItem((state) =>
{
running = true;
// 侦听线程
Thread.CurrentThread.IsBackground = false;
try
{
while (running)
{
if (_tcpListener.Pending())
{
var c = _tcpListener.AcceptTcpClient();
ThreadPool.QueueUserWorkItem((st) =>
{
try
{
Thread.CurrentThread.IsBackground = true;
var handler = new P1Server(c, GlobalVar.server);
handler.Handle();
}
catch (Exception ex)
{
Trace.Write("服务处理线程(直连)异常退出:" + ex.ToString());
}
DebugHelper.PrintAll();
});
}
else
{
Thread.Sleep(100);
}
}
}
catch (Exception ex)
{
Trace.Write("主侦听线程异常退出:" + ex.ToString());
}
});
}
catch (Exception ex)
{
Trace.Write(ex.ToString());
}
}
protected override void OnStop()
{
running = false;
}
private void startHttpListener(int port)
{
#if DEBUG
var httpServer = new SimpleHttpServer(port, GlobalVar.server, null);
#else
var httpServer = new SimpleHttpServer(port, GlobalVar.server, null);
#endif
httpServer.Listen();
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化