Event Handlers are being called from a different thread.
See original GitHub issueI am trying to replace another irc library with your library. I am using it with Mono. It seems to connect okay, but when an event handler, receives an event and I go to update the user interface, I get an “xxx can only be called from the main thread”.
I don’t know much about threading, but it seems to me that you should be returning the event on the main thread.
`public void Connect(Server server, bool useSsl, Profile userProfile) { // if already connected?
IrcUserRegistrationInfo user = new IrcUserRegistrationInfo();
user.UserName = userProfile.username;
user.NickName = userProfile.nickname;
user.RealName = userProfile.realname;
user.Password = userProfile.password;
ircClient = new StandardIrcClient();
ircClient.FloodPreventer = new IrcStandardFloodPreventer(4, 2000);
ircClient.Connected += ircClient_Connected;
// ircClient.ConnectFailed += ircClient_ConnectFailed;
/// ircClient.Disconnected += ircClient_Disconnected;
// ircClient.Error += ircClient_Error;
// ircClient.ProtocolError += ircClient_ProtocolError;
// ircClient.Registered += ircClient_Registered;
// ircClient.MotdReceived += ircClient_MotdReceived;
// ircClient.NetworkInformationReceived += ircClient_NetworkInformationReceived;
// ircClient.ServerVersionInfoReceived += ircClient_ServerVersionInfoReceived;
// ircClient.ServerTimeReceived += ircClient_ServerTimeReceived;
// ircClient.ServerLinksListReceived += ircClient_ServerLinksListReceived;
// ircClient.ServerStatsReceived += ircClient_ServerStatsReceived;
// ircClient.WhoReplyReceived += ircClient_WhoReplyReceived;
// ircClient.WhoIsReplyReceived += ircClient_WhoIsReplyReceived;
// ircClient.WhoWasReplyReceived += ircClient_WhoWasReplyReceived;
// ircClient.ChannelListReceived += ircClient_ChannelListReceived;
if (useSsl && server.sslPorts.Length > 0)
{
ircClient.Connect(server.hostName, server.sslPorts[0], true, user);
}
else if (useSsl == false && server.ports.Length > 0)
{
ircClient.Connect(server.hostName, server.ports[0], false, user);
}
}
private void ircClient_Connected(object sender, EventArgs e) { txtSend.enabled = true; // ERROR
}
`
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Is it possible to put an event handler on a different thread ...
Normally AutoResetEvents is called be a separate thread, so I guess that means that the event handler is on the same thread as...
Read more >Is opening a new thread for each event you want to handle ...
My question is, how is such a thing implemented when wanting to check for multiple events such as game events. The event loop...
Read more >How to make thread-safe calls to controls - Windows Forms ...
There are two ways to safely call a Windows Forms control from a thread that didn't create that control. Use the System.Windows.Forms.
Read more >Event Handler Timeout Makes Calling Thread To ...
This code sample demonstrates how BindableEvents, like all Events, create threads of each connected function. Even if one errors, like ohNo does ...
Read more >Race condition in event-handling thread example #1291
I would like to implement an event thread that forcibly processes all events, i.e. even when I use synchronous I/O functions on other...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

for WPF it is System.Windows.Application.Dispatcher.Invoke(someAction);
Okay, worked out how to use it with unity.
Thanks for the feedback.