admin管理员组文章数量:1405298
So basically game is getting added to users even if I open it fast and close but it doesn't get removed
if (oldPresence.Activities.Count(e => Convert.ToString(e.Type) == "Playing") >
newPresence.Activities.Count(e => Convert.ToString(e.Type) == "Playing")) {
foreach (var game in oldPresence.Activities) {
if (!newPresence.Activities.Contains(game)) {
gameName = game.Name;
break;
}
}
shouldDo = true;
}
// this is basically handler to closing game
if (oldPresence.Activities.Any() && shouldDo == true) {
// we create User object here and also get time game was open
User localUser =
new User(Convert.ToString(user), Convert.ToString(gameName));
if (users.Any(e => e.userName == localUser.userName &&
e.game == localUser.game)) {
Console.WriteLine(gameName);
int index = users.FindIndex(u => u.userName == localUser.userName &&
u.game == localUser.game);
Console.WriteLine(DateTime.Now.Subtract(users[index].date));
// dataBase.AddPlayerGame(1, "saba",
// DateTime.Now.Subtract(users[index].date));
users.RemoveAt(index);
}
}
if (shouldDo == false &&
user.Activities.Any(e => Convert.ToString(e.Type) == "Playing")) {
string newGame = Convert.ToString(newPresence.Activities.First().Name);
User localUser = new User(Convert.ToString(user), newGame);
if (!users.Any(e => e.userName == localUser.userName &&
e.game == localUser.game)) {
users.Add(localUser);
Console.WriteLine("game added");
}
}
I also run method in dedicated thread like this
Thread test =
new Thread(() => ActivityHandler(user, oldPresence, newPresence)) {
Name = Convert.ToString(ThreadCount)
};
ThreadCount++;
test.Start();
and I call this last method (ThreadManager) on PresenceUpdated
I have tried to use lock but it doesn't work, also Join doesn't work and running it on a single thread doesn't work too.
I don't have slow internet (Download Mbps 31.84 and Upload Mbps 2.80);
Also worth mentioning that most of the test was done with adding multiple games in discord with Registered games and removing them fast.
So basically game is getting added to users even if I open it fast and close but it doesn't get removed
if (oldPresence.Activities.Count(e => Convert.ToString(e.Type) == "Playing") >
newPresence.Activities.Count(e => Convert.ToString(e.Type) == "Playing")) {
foreach (var game in oldPresence.Activities) {
if (!newPresence.Activities.Contains(game)) {
gameName = game.Name;
break;
}
}
shouldDo = true;
}
// this is basically handler to closing game
if (oldPresence.Activities.Any() && shouldDo == true) {
// we create User object here and also get time game was open
User localUser =
new User(Convert.ToString(user), Convert.ToString(gameName));
if (users.Any(e => e.userName == localUser.userName &&
e.game == localUser.game)) {
Console.WriteLine(gameName);
int index = users.FindIndex(u => u.userName == localUser.userName &&
u.game == localUser.game);
Console.WriteLine(DateTime.Now.Subtract(users[index].date));
// dataBase.AddPlayerGame(1, "saba",
// DateTime.Now.Subtract(users[index].date));
users.RemoveAt(index);
}
}
if (shouldDo == false &&
user.Activities.Any(e => Convert.ToString(e.Type) == "Playing")) {
string newGame = Convert.ToString(newPresence.Activities.First().Name);
User localUser = new User(Convert.ToString(user), newGame);
if (!users.Any(e => e.userName == localUser.userName &&
e.game == localUser.game)) {
users.Add(localUser);
Console.WriteLine("game added");
}
}
I also run method in dedicated thread like this
Thread test =
new Thread(() => ActivityHandler(user, oldPresence, newPresence)) {
Name = Convert.ToString(ThreadCount)
};
ThreadCount++;
test.Start();
and I call this last method (ThreadManager) on PresenceUpdated
I have tried to use lock but it doesn't work, also Join doesn't work and running it on a single thread doesn't work too.
I don't have slow internet (Download Mbps 31.84 and Upload Mbps 2.80);
Also worth mentioning that most of the test was done with adding multiple games in discord with Registered games and removing them fast.
Share edited Mar 8 at 2:41 nalka 2,3882 gold badges18 silver badges34 bronze badges asked Mar 7 at 21:14 skami0_0skami0_0 413 bronze badges 1- Please share a minimal reproducible example. – mjwills Commented Mar 8 at 3:37
1 Answer
Reset to default 0My best guess is that you're unable to locate the correct user, possibly because the game
property doesn't match the value you're expecting. I'd recommend adding an else
statement after the if
's where you're trying to find the user and logging the fact that you were unable to locate the user. This should help narrow down where it's going wrong.
本文标签: cWhy discord net doesn39t work when I open and close games fastStack Overflow
版权声明:本文标题:c# - Why discord net doesn't work when I open and close games fast - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744909309a2631814.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论