我正在使用 Windows 服务与使用 Udp 套接字的设备进行通信。在服务的构造函数中,我有以下代码
public Service1()
{
try
{
EventLog eventLog1 = new System.Diagnostics.EventLog();
eventLog1.Source = "Alert Control Service";
eventLog1.Log = "Application";
//InitializeComponent();
//TextBox settings
//Wire-up the EventHandler
//Create the UdpClient
server = new UdpClient(port);
serverForAdam = new UdpClient(6768);
//Define a Receive point
receivePoint = new IPEndPoint(new IPAddress(ip), port);
IPAddress adam1 = IPAddress.Parse("172.16.2.252");
adamReceivePoint = new IPEndPoint(adam1, 1025);
string channel = "";
//read alarm configuration from database
RegistryKey baseKey = null;
if (Environment.Is64BitOperatingSystem)
{
baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
}
else
{
baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
}
RegistryKey myKey = baseKey.OpenSubKey("SOFTWARE\\AlarmConfig", true);
if (myKey == null)
{
eventLog1.WriteEntry("No AlarmConfig Registry key");
}
string regString = (string)myKey.GetValue("database");
string decryptString = Crypto.DecryptStringAES(regString, "1234");
SQLConn.ConnectionString = decryptString;
SQLConn.Open();
}
catch (Exception ex)
{
TextWriter tw = new StreamWriter("c:\\error.txt");
// write a line of text to the file
tw.WriteLine(ex.Message);
// close the stream
tw.Close();
}
}
这将写一行:阻塞操作被error.txt中的wsacancelblockingcall调用中断
那是什么原因呢。我尝试将服务作为普通的 Windows 应用程序运行。没关系,消息不存在。请帮忙。