FPGA_WebLab/server/src/MsgBus.cs

45 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/// <summary>
/// 多线程通信总线
/// </summary>
public static class MsgBus
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private static readonly UDPServer udpServer = new UDPServer(1234, 12);
/// <summary>
/// 获取UDP服务器
/// </summary>
public static UDPServer UDPServer { get { return udpServer; } }
private static bool isRunning = false;
/// <summary>
/// 获取通信总线运行状态
/// </summary>
public static bool IsRunning { get { return isRunning; } }
/// <summary>
/// 通信总线初始化
/// </summary>
/// <returns>无</returns>
public async static void Init()
{
if (!ArpClient.IsAdministrator())
{
logger.Error($"非管理员运行ARP无法更新请用管理员权限运行");
// throw new Exception($"非管理员运行ARP无法更新请用管理员权限运行");
}
udpServer.Start();
isRunning = true;
}
/// <summary>
/// 关闭通信总线
/// </summary>
/// <returns>无</returns>
public static void Exit()
{
udpServer.Stop();
isRunning = false;
}
}