我正在使用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应用程序运行。没关系,消息不存在。请帮忙。