wiz0u / WTelegramClient

Telegram Client API (MTProto) library written 100% in C# and .NET
https://wiz0u.github.io/WTelegramClient/
MIT License
996 stars 164 forks source link

wtelegramm.session file is not threadsafe #172

Closed Kors1981 closed 1 year ago

Kors1981 commented 1 year ago

I'm using the library in multiple instances, and File is get locked, as far as I see there is no locking mechanism on the session file to avoid this issue, The exception I get can be seen below. System.IO.IOException","Message":"The process cannot access the file '/app/WTelegram.session' because it is being used by another process.

Kors1981 commented 1 year ago

multiply instances of the library may use some better approach to lock the file

wiz0u commented 1 year ago

That's normal. You can't have multiple instances using the same session.

But you can have multiple instances controlling the same Telegram account by creating multiple sessions (in separate session files) for this account.

It's done the same way as controlling multiple accounts. You'll need to answer a verification_code for each new session you create. See this FAQ: https://wiz0u.github.io/WTelegramClient/FAQ#multiple-users

wiz0u commented 1 year ago

Additionally, the WTelegram.Client IS thread-safe, you CAN launch API calls in parallel from different tasks/threads (on the same Client instance)