# SendChatTo() not working inside callback function

**URL:** <https://devforum.zoom.us/t/sendchatto-not-working-inside-callback-function/18575>\
**Category:** Windows\
**Created:** [May 21, 2020, 11:54am UTC](https://devforum.zoom.us/t/sendchatto-not-working-inside-callback-function/18575 "2020-05-21T11:54:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam.decrock](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/sam.decrock/32/8656_2.png) [@sam.decrock](https://devforum.zoom.us/u/sam.decrock)\
**Post date:** [May 21, 2020, 11:54am UTC](https://devforum.zoom.us/t/sendchatto-not-working-inside-callback-function/18575/1 "2020-05-21T11:54:33Z")

</div>

When I send a command via [socket.io](http://socket.io) to my C# Zoom application, which then sends a chat using `SendChatTo()`, the SDK returns with error `15`. If I’m correct, that’s `SDKERR_INTELNAL_ERROR`.

If do the exact same command when someone connects, no error.

When I execute other commands, like `spotlightVideo()` from a [socket.io](http://socket.io) callback function, it also works.

What could be wrong?

Sam

---

<div class="post-metadata">

**Author:** ![carson.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/carson.zoom/32/785_2.png) [@carson.zoom](https://devforum.zoom.us/u/carson.zoom)\
**Post date:** [May 23, 2020, 12:45am UTC](https://devforum.zoom.us/t/sendchatto-not-working-inside-callback-function/18575/2 "2020-05-23T00:45:40Z")

</div>

Hi Sam,

Thanks for the post. We have not tested our C# wrapper with [socket.io](http://socket.io) before, could you provide an example(maybe some code snippet or steps to reproduce would be really helpful) and what are the parameters you are passing to trigger the interface? We could look into this and further investigate and figure out why.

Thanks!

---

<div class="post-metadata">

**Author:** ![sam.decrock](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/sam.decrock/32/8656_2.png) [@sam.decrock](https://devforum.zoom.us/u/sam.decrock)\
**Post date:** [May 23, 2020, 4:59pm UTC](https://devforum.zoom.us/t/sendchatto-not-working-inside-callback-function/18575/3 "2020-05-23T16:59:17Z")

</div>

Hi @carson.zoom,

Here’s a code sample. I commented what works and what doesn’t. I guess it might have something to do with threads. I suspect the socket’s callbacks are happening in another thread, but I’m not sure:

```
using Quobject.SocketIoClientDotNet.Client;

namespace zoom_sdk_demo
{

  public partial class start_join_meeting : Window
  {

    const string staysafeButtonServerEndpoint = "https://myserver";

    IMeetingServiceDotNetWrap meetingService = ZOOM_SDK_DOTNET_WRAP.CZoomSDKeDotNetWrap.Instance.GetMeetingServiceWrap();
    IMeetingParticipantsControllerDotNetWrap participantsController = ZOOM_SDK_DOTNET_WRAP.CZoomSDKeDotNetWrap.Instance.GetMeetingServiceWrap().GetMeetingParticipantsController();
    IMeetingVideoControllerDotNetWrap videoController = ZOOM_SDK_DOTNET_WRAP.CZoomSDKeDotNetWrap.Instance.GetMeetingServiceWrap().GetMeetingVideoController();
    IMeetingChatControllerDotNetWrap chatController = ZOOM_SDK_DOTNET_WRAP.CZoomSDKeDotNetWrap.Instance.GetMeetingServiceWrap().GetMeetingChatController();

    Socket socket = IO.Socket(staysafeButtonServerEndpoint);

    uint userInSpotlight = 0;
    

    public start_join_meeting()
    {
      RegisterCallBack();
      initSocketIO();
      InitializeComponent();
    }

    public void initSocketIO()
    {
      
      socket.On(Socket.EVENT_CONNECT, () =>
      {
        Console.WriteLine("Connected to socket.io server, sending hello.");
        socket.Emit("room", "zoom");
      });

      socket.On("SpotlightVideo", (data) =>
      {
        Console.WriteLine("> socketio got 'SpotlightVideo'");
        if (meetingService.GetMeetingStatus() != MeetingStatus.MEETING_STATUS_INMEETING) { Console.WriteLine("> not in meeting"); return; }
      
        uint userId = (uint)Convert.ToInt32(data);

        Console.WriteLine("SpotlightVideo " + userId);
        videoController.SpotlightVideo(true, userId); // THIS WORKS
      });

      socket.On("SendChatTo", (data) =>
      {
        if (meetingService.GetMeetingStatus() != MeetingStatus.MEETING_STATUS_INMEETING) { Console.WriteLine("> not in meeting"); return; }

        var dataObject = (JObject)data;
        uint userId = (uint)Convert.ToInt32(dataObject["userId"]);
        string text = (string)dataObject["text"];

        chatController.SendChatTo(userId, text); // THIS DOESN'T WORK
      });

      
    }

    public void onUserJoin(Array userIds)
    {
      
      if (null == (Object)userIds) return;

      foreach (uint userId in userIds)
      {
        var user = participantsController.GetUserByUserID(userId);
        chatController.SendChatTo(userId, "Welcome " + user.GetUserNameW()); // THIS WORKS
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![carson.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/carson.zoom/32/785_2.png) [@carson.zoom](https://devforum.zoom.us/u/carson.zoom)\
**Post date:** [May 28, 2020, 9:38am UTC](https://devforum.zoom.us/t/sendchatto-not-working-inside-callback-function/18575/4 "2020-05-28T09:38:24Z")

</div>

Hi @sam.decrock,

Thanks for the reply and thanks for providing the code snippet. Based on the code, everything looks good so I am not sure why you are getting unexpected results. Would you mind providing an SDK log for us to further investigate? You may set the attribute enableLogByDefault = true at SDK initialization and find the SDK log in %appdata%/zoomsdk/logs/

Thanks!

---

<div class="post-metadata">

**Author:** ![sam.decrock](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/sam.decrock/32/8656_2.png) [@sam.decrock](https://devforum.zoom.us/u/sam.decrock)\
**Post date:** [June 6, 2020, 12:00pm UTC](https://devforum.zoom.us/t/sendchatto-not-working-inside-callback-function/18575/5 "2020-06-06T12:00:25Z")

</div>

Hi, thanks,  
This is the log that shows up in the folder. I hope you guys can read it as it seems a bit encrypted if you ask me 😉

> **[zoom\_sdk\_demo.vshost.exe\_Video\_0.log](https://wetransfer.com/downloads/aa21179451d1b0b7b9f6f6b95417cd5f20200606120013/732237)**
>
> 1 file sent via WeTransfer, the simplest way to send your files around the world

---

<div class="post-metadata">

**Author:** ![sam.decrock](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/sam.decrock/32/8656_2.png) [@sam.decrock](https://devforum.zoom.us/u/sam.decrock)\
**Post date:** [June 6, 2020, 12:22pm UTC](https://devforum.zoom.us/t/sendchatto-not-working-inside-callback-function/18575/6 "2020-06-06T12:22:26Z")

</div>

Ok, I was able to fix it by wrapping my code using this method: [https://stackoverflow.com/questions/11625208/accessing-ui-main-thread-safely-in-wpf](https://stackoverflow.com/questions/11625208/accessing-ui-main-thread-safely-in-wpf)

`Application.Current.Dispatcher.Invoke(new Action(() => { // my code }));`

For example:

```
Application.Current.Dispatcher.Invoke(new Action(() => {
    Console.WriteLine("SendChatTo " + userId + ": " + text);
    var ret = chatController.SendChatTo(userId, text);
    Console.WriteLine(ret);
}));
```

---

<div class="post-metadata">

**Author:** ![carson.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/carson.zoom/32/785_2.png) [@carson.zoom](https://devforum.zoom.us/u/carson.zoom)\
**Post date:** [June 9, 2020, 5:46am UTC](https://devforum.zoom.us/t/sendchatto-not-working-inside-callback-function/18575/7 "2020-06-09T05:46:56Z")

</div>

Hi @sam.decrock,

Thanks for the reply, the log, and the solution. Glad to hear that this issue has been resolved. 🙂

---

<div class="post-metadata">

**Author:** ![DeveloperBot](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/developerbot/32/12632_2.png) [@DeveloperBot](https://devforum.zoom.us/u/DeveloperBot)\
**Post date:** [August 21, 2020, 9:56pm UTC](https://devforum.zoom.us/t/sendchatto-not-working-inside-callback-function/18575/8 "2020-08-21T21:56:39Z")

</div>

Closed on August 21, 2020, 9:56pm UTC


