事件,委托,DLL-捕获事件以解析其值? [英] Events, Delegates, DLL - capture Event an parse it's values?
问题描述
我目前停留在活动和代表会议上.我有一个包含事件的dll,例如PlayerJoiningEventArgs事件.它是BF3Rcon.NET项目的一部分.我的目标是捕获事件(如果已触发)并返回事件的值!
我创建了一个名为:
的对象
Hi,
i''m currently stuck on Events and Delegates. I have an dll containing Events - for example the PlayerJoiningEventArgs Event. It''s a part of the BF3Rcon.NET Project. My goal is to capture the Event if it''s fired and return the values of the events!
I create an Object called:
RconClient client = new RconClient();
然后分配:
and then assign:
client.PlayerJoining += new EventHandler<PlayerJoinInEventArgs>((playersender, playerevent) => OnPlayerJoining(playerevent));
其中OnPlayerJoining是一种方法,并在调用Event时被触发.
where OnPlayerJoining is a method and is fired when the Event is called.
protected virtual void OnPlayerJoining(PlayerJoiningEventArgs e)
{
MessageBox.Show(e.Name);
}
我的问题现在是,自从我收到消息以来,我无法将变量e.Name返回给我的Form1,该Form1与客户端Object !?不是同一线程. -MessageBox在这里运作良好! -向我显示正确的玩家名称.那么,我应该怎么做才能将变量e.Name传递给Form1线程?
谢谢您的任何建议或摘要!
致以最诚挚的问候
Ralf
My Problem is now, that i can''t return the variable e.Name to my Form1 since i get the Message, that the Form1 is not the same Thread as the client Object!?. - MessageBox works well here! - Shows me correct Playername. So, what should i do to get the variable e.Name to my Form1 Thread?
Thank you for any suggestions or snippets!
With best Regards
Ralf
推荐答案
好吧,我没有《战地风云3》,所以我无法测试一下,但是如果您得到的错误是跨线程操作错误,那么类似这可能会有所帮助.
Well I don''t have Battlefield 3 so I cannot test to be sure but if the error you are getting is a cross thread operation error then something like this might help.
string name;
private delegate void OnPlayerJoiningCallback(PlayerJoiningEventArgs e);
protected virtual void OnPlayerJoining(PlayerJoiningEventArgs e)
{
if (this.InvokeRequired)
{
OnPlayerJoiningCallback opjc =
new OnPlayerJoiningCallback(OnPlayerJoining);
this.Invoke(opjc, new object[] { e });
}
else
{
this.name = e.Name;
}
}
这篇关于事件,委托,DLL-捕获事件以解析其值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!