我有以下项目和类(在C#中):
IMyService
public interface IMyService
{
void OnKeyPressed(object sender, EventArgs keyPressedArgs);
}
MyService (引用 IMyService )
public class MyService : IMyService
{
public void OnKeyPressed(object sender, EventArgs keyPressedArgs)
{
// UNSURE WHAT TO PUT HERE
}
}
接收者(参考 IMyService 和 MyService )
public partial class Receiver : IMyService
{
public static MyService Service; // initialized elsewhere
public void OnKeyPressed(object sender, EventArgs keyPressedArgs)
{
// Updates xaml UI here
...
}
}
其他课程:
发件人(参考 IMyService , MyService 和接收器)
public partial class Sender
{
public MyService Service;
public Sender(ReceiverViewMainWindow window)
{
MainWindow = window;
MainWindow.Loaded += MainWindowOnLoaded;
}
private void MainWindowOnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
// Connects to the service
...
Service = // connects here
...
KeyboardListener = new LowLevelKeyboardListener();
KeyboardListener.OnKeyPressed += OnKeyPressed;
KeyboardListener.HookKeyboard();
}
public void OnKeyPressed(object sender, EventArgs args)
{
Service.OnKeyPressed(sender, args);
}
更新
发件人将在PC#1上运行。接收器将在PC#2上运行。我的目标是通过服务将从PC#1(发送者)收集的击键发送到PC#2(接收者)。
我知道要将PC#1(发送者)的击键发送到服务,我只需要使用发送者的OnKeyPressed()方法来调用接收者中创建的MyService实例的OnKeyPressed()方法。但是,**我不知道如何将OnKeyPressed()方法的击键发送到接收器到ReceiverLogic.cs。如果我尝试将MyService中的引用添加到Receiver,我会收到循环引用错误,因为Receiver引用了MyService。
如何在接收器内访问接收器服务中收到的击键数据?我想使用数据更新接收器的UI等。任何帮助表示赞赏。谢谢。