Ошибка 1053 при запуске службы - C#
Формулировка задачи:
Уважаемые подскажите в какую сторону копать, служба при запуске дает ошибку 1053, и висит в состоянии "Запуск"
using Ionic.Zip; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.IO; using System.Linq; using System.Net; using System.Net.Sockets; using System.Runtime.Serialization.Formatters.Binary; using System.ServiceProcess; using System.Text; using System.Threading; using System.Threading.Tasks; namespace Hook { public partial class Hook : ServiceBase { public Hook() { InitializeComponent(); } protected override void OnStart(string[] args) { string ip = "127.0.0.1"; IPHostEntry iphe = Dns.Resolve(ip); IPAddress ipa = iphe.AddressList[0]; IPEndPoint ipep = new IPEndPoint(ipa, 7700); Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); s.Bind(ipep); s.Listen(20); while (true) { Socket handler = s.Accept(); string data = null; while (true) { byte[] bytes = new byte[1024]; handler.Receive(bytes); data += Encoding.UTF8.GetString(bytes); if (data.IndexOf("") > -1) { Console.WriteLine(data); Searcher searcher = new Searcher(@"D:\Test", data); searcher.Run(); break; } } } } class Searcher { FileSystemWatcher fsw; public Searcher(string path, string filter) { fsw = new FileSystemWatcher(path, filter); fsw.Created += new FileSystemEventHandler(fsw_Changed); } public void Run() { fsw.EnableRaisingEvents = true; } void fsw_Changed(object sender, FileSystemEventArgs e) { try { File.Move(e.FullPath, @"D:\Test1" + e.Name); /*ZipFile zip = new ZipFile(@"D:\Test" + e.Name); zip.ExtractAll(@"D:\Test");*/ fsw.EnableRaisingEvents = false; //отключаем слежение } catch { } } } protected override void OnStop() { } } }
Решение задачи: «Ошибка 1053 при запуске службы»
textual
Листинг программы
using Ionic.Zip; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.IO; using System.Linq; using System.Net; using System.Net.Sockets; using System.Runtime.Serialization.Formatters.Binary; using System.ServiceProcess; using System.Text; using System.Threading; using System.Threading.Tasks; namespace Hook { public partial class Hook : ServiceBase { public Hook() { InitializeComponent(); } protected override void OnStart(string[] args) { MyThread mt = new MyThread(); Thread t1 = new Thread(new ThreadStart(mt.hook)); t1.Start(); } protected override void OnStop() { } } } public class MyThread { public void hook() { string ip = "127.0.0.1"; IPHostEntry iphe = Dns.Resolve(ip); IPAddress ipa = iphe.AddressList[0]; IPEndPoint ipep = new IPEndPoint(ipa, 7700); Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { s.Bind(ipep); s.Listen(20); while (true) { Socket handler = s.Accept(); string data = null; while (true) { byte[] bytes = new byte[1024]; handler.Receive(bytes); data += Encoding.UTF8.GetString(bytes); if (data.IndexOf("") > -1) { Thread t1 = new Thread(new ParameterizedThreadStart(func)); t1.Start(data); Console.WriteLine(data); break; } } } } catch { } } static void func(object obj) { if (obj != null) { Searcher search = new Searcher(@"D:\Test", Convert.ToString(obj)); search.Run(); } } class Searcher { FileSystemWatcher fsw; public Searcher(string path, string filter) { fsw = new FileSystemWatcher(path, filter); fsw.Created += new FileSystemEventHandler(fsw_Changed); } public void Run() { fsw.EnableRaisingEvents = true; } void fsw_Changed(object sender, FileSystemEventArgs e) { try { File.Move(e.FullPath, @"D:\Test1" + e.Name); /*ZipFile zip = new ZipFile(@"D:\Test" + e.Name); zip.ExtractAll(@"D:\Test");*/ fsw.EnableRaisingEvents = false; //отключаем слежение } catch { } } } }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д