Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CollectUsersChats: error Collection was modified; enumeration operation may not execute. #266

Closed
devtunnelx opened this issue Jun 30, 2024 · 3 comments
Labels
question General question or discussion

Comments

@devtunnelx
Copy link

devtunnelx commented Jun 30, 2024

Version: 4.1.2-dev.7

I'm having an issue when using UpdateManager.CollectUsersChats()

Exception keeps thrown after running the app (like 30 minutes or 45 later)

Collection was modified; enumeration operation may not execute.

Current code:

  var users = new Dictionary<long, User>();
  var chats = new Dictionary<long, ChatBase>();

                lock (_updatesManagerLock)
                {
                    var manager = _updateManagers[client];
                    manager.CollectUsersChats(users, chats);
   
                }

Even when using _lock and thread safety masques, i still get the error at manager.CollectUsersChats(users, chats);

@wiz0u
Copy link
Owner

wiz0u commented Jul 9, 2024

What are you trying to achieve exactly?

You're not supposed to call manager.CollectUsersChats

@devtunnelx
Copy link
Author

What are you trying to achieve exactly?

You're not supposed to call manager.CollectUsersChats

Basically, my app listen to incoming Telegram updates and I want to get the sender and chat information from the update then enqueue it to be processed by queue consumers.

If using manager.CollectUsersChats is not the right way, what would you suggest?

thank you sir

@wiz0u
Copy link
Owner

wiz0u commented Jul 10, 2024

Use Manager.UserOrChat or Manager.Users/Chats dictionaries to resolve peers & ids into details

or call structure.CollectUsersChats(Manager.Users, Manager.Chats); after an API call that return a structure which contains users/chats

As demonstrated in https://github.com/wiz0u/WTelegramClient/blob/master/Examples/Program_ListenUpdates.cs

See also these explanations:

@wiz0u wiz0u closed this as completed Jul 10, 2024
@wiz0u wiz0u added the question General question or discussion label Jul 27, 2024
@wiz0u wiz0u changed the title Collection was modified; enumeration operation may not execute. CollectUsersChats: error Collection was modified; enumeration operation may not execute. Jul 27, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question General question or discussion
Projects
None yet
Development

No branches or pull requests

2 participants