question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Event Handlers are being called from a different thread.

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Insirecommented, Oct 21, 2018

for WPF it is System.Windows.Application.Dispatcher.Invoke(someAction);

0reactions
hypodynecommented, Oct 26, 2018

Okay, worked out how to use it with unity.

Thanks for the feedback.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found