protected override void OnStart(string[] args) { //Assembly.LoadFrom(@"InterceptKeys.exe"); //var instance = AppDomain.CurrentDomain.CreateInstance("InterceptKeys", "InterceptKeys.InterceptKeys"); //var instance = Activator.CreateInstance(Type.GetType("InterceptKeys.InterceptKeys,InterceptKeys")); Task.Factory.StartNew(() => { var pipe = new Receiver(); pipe.Data += (data) => { LogManager.Logger.Debug(string.Format("收到数据:{0}", string.Join(",", data))); }; if (pipe.ServiceOn() == false) { LogManager.Logger.Error(pipe.error); } //start socket server this.serverGuid = Guid.NewGuid(); this.server = new BasicSocketServer(); this.server.ReceiveMessageEvent += (handler, message) => { BasicMessage receivedMessage = (BasicMessage)message; byte[] buffer = receivedMessage.GetBuffer(); if (buffer.Length > 1000) { LogManager.Logger.Debug(string.Format("Received a long message of {0} bytes", receivedMessage.MessageLength), "Socket Server"); return; } string s = System.Text.ASCIIEncoding.Unicode.GetString(buffer); LogManager.Logger.Debug(string.Format("Received Message:{0} from {1}", s, receivedMessage.ClientUID)); var client = server.GetClientList().FirstOrDefault(c => c.ClientUID == handler.ToString()); client.TcpSocketClientHandler.SendAsync(new BasicMessage(this.serverGuid, System.Text.ASCIIEncoding.Unicode.GetBytes("收到"))); }; this.server.ConnectionEvent += (handler) => { LogManager.Logger.Debug(string.Format("A client is connected to the server"), "Socket Server"); }; this.server.CloseConnectionEvent += (handler) => { LogManager.Logger.Debug(string.Format("A client is disconnected from the server"), "Socket Server"); }; this.server.Init(new IPEndPoint(IPAddress.Loopback, 8100)); this.server.StartUp(); ClosePreProcess(); Process.Start(@"InterceptKeys.exe"); }); }
private void Main_Load(object sender, EventArgs e) { /* Classes Startup */ this.Account = new Accounts(); /* Server Configuration */ this.server = new BasicSocketServer(); this.server.ReceiveMessageEvent += new SocketServerLib.SocketHandler.ReceiveMessageDelegate(server_ReceiveMessageEvent); this.server.ConnectionEvent += new SocketConnectionDelegate(server_ConnectionEvent); this.server.CloseConnectionEvent += new SocketConnectionDelegate(server_CloseConnectionEvent); this.server.Init(new IPEndPoint(Core.ADDRESS, Core.PORT)); this.server.StartUp(); /* Initial SplashScreen */ this.splashscreen = new SplashScreen(); this.Hide(); Thread thread = new Thread(new ThreadStart(this.ShowSplashScreen)); thread.Start(); HardWorker hw = new HardWorker(); hw.ProgressChanged += (o, ex) => { this.splashscreen.UpdateProgress(ex.Progress); }; hw.HardWorkDone += (o, ex) => { done = true; this.Show(); }; hw.DoHardWork(); }