nikeee / TeamSpeak3QueryApi

.NET wrapper for the TeamSpeak 3 Query API
https://nikeee.github.io/TeamSpeak3QueryAPI
GNU General Public License v3.0
59 stars 16 forks source link

Notifications not working correctly? #18

Closed almdandi closed 6 years ago

almdandi commented 6 years ago

Hallo,

i'm having a weird problem with notifications, they never get fired. I see the servernotifyregister message in the debug window and they even got confirmed (error id=0 msg=ok) but if i switch channels or write a private message, no notify... message abiers in the debug window.

First i tried to set a breakpoint at but it never got fired.

Then i created 3 test projects.

The problem abiers only when the TeamSpeak3 QueryAPI library is used. With the simple version, i receive the notify messages.

I also checked the tcp communication with wireshark and in all 3 cases the notify messages got send from the teamspeak server.

Maybe someone can confirm that notification are working correctly and maybe can give me a tipp, what i'm doing wrong.

I'm using Visual Studio 15.5.3 with .Net Framework 4.7.1 and .Net Core SDK 2.1.4. I tested it on 3 different PC's, always with the same result.

nikeee commented 6 years ago

I'll take a look at that.

almdandi commented 6 years ago

Hey,

i had time to investigate the problem a little bit more and i found a strange thing to me.

Test Code:

var rc = new TeamSpeakClient("192.168.102.128", 10011);
await rc.Connect();

await rc.Login("serveradmin", "rL8fc+Ew");
await rc.UseServer(1);

await rc.RegisterTextServerNotification();
await rc.RegisterTextPrivateNotification();

rc.Subscribe<TextMessage>(data => data.ForEach(msg => Console.WriteLine($"Event - Message: {msg.Message}, From: {msg.InvokerName}, Type: {msg.TargetMode}")));

Console.WriteLine("Done");

Thread.Sleep(10000);

await rc.SendGlobalMessage("Global Test 1");

Thread.Sleep(10000);

await rc.SendGlobalMessage("Global Test 2");

while (true)
{
    Thread.Sleep(100);
}

The first thing i found out was, when the server send a message, the notify message gets processed and the the callback method gets execuded. Also if there ware notify messages send before, no matter by who, thay will also gets processed.

So i added a Debug.WriteLine("Command done"); after the if statements in QueryClient.ResponseProcessingLoop method, to check when a command processing is finished.

The weird thing is, normally i should get Command done after every command i send to the server but i don't. The last Command done on the end of every "section" is missing. By section i mean, in the program are 3 "sections" between those "sections" is a 10 second delay (Thread.Sleep(10000);). But when the next section gets executed i get the missing Command done from the previous section.

Then i seted a Breakpoint at (with a condition count=4 to skip the messages form the start up), to see why the debug message is not executing. It's turns out that the Task stops completely after "InvokeResponse". The cmd window pops back in foreground and the yellow debug arrow in VS disappears. But when the next section gets executed the yellow debug arrow comes back, one line below, i stopped debugging before.

It seems like the Task gets paused when there's no work and resumed when there is. The question now is why the task only gets resumed when the program sends something but at the point for time i have no idea

nikeee commented 6 years ago

Interesing find. I'm currently lacking a server to test on. Does it behave the same way if you use await Task.Delay(10000); instead of Thread.Sleep(10000);? Maybe the thread gets blocked somehow.

almdandi commented 6 years ago

Wow. Yeah that was it. Thank you!