You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.8 KiB
C#

using DevExpress.CodeParser;
using IPCLib;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RunWellSectionApp
{
public class IpcMmfClass
{
public MmfCommunication m_mmf;
public bool m_bUse = false;
public Process m_process;
public string m_MemoryId = "";
public Timer _statusTimer;
public IpcMmfClass()
{
Guid tGuid = Guid.NewGuid();
m_MemoryId = tGuid.ToString();
}
public async void Init(Action<string> OnDataReceived, Action OnConnected, Action<string> OnDisconnected,
Action<string>OnPeerFrozen , Action<string> OnMmfError)
{
try
{
// 1. 初始化通讯(服务端)
m_mmf = new MmfCommunication(m_MemoryId, isServer: true, "KEP");
m_mmf.DataReceived += OnDataReceived;
m_mmf.Connected += OnConnected;
m_mmf.Disconnected += OnDisconnected;
m_mmf.PeerFrozen += OnPeerFrozen;
m_mmf.ErrorOccurred += OnMmfError;
await m_mmf.StartAsync();
// 3. 启动状态显示定时器
//_statusTimer = new Timer { Interval = 1000 };
//_statusTimer.Tick += (s, e) => UpdateStatus();
//_statusTimer.Start();
}
catch (Exception ex)
{
MessageBox.Show($"KEP 启动失败:{ex.Message}");
}
}
public void Release()
{
_statusTimer?.Stop();
_statusTimer?.Dispose();
m_mmf?.Dispose();
}
}
}