ertaboy356b
Old School Gamer
- Reaction score
- 86
So creating this monitoring application is a really big challenge for me. Not only that it requires a large amount of database interaction, but it also needs to be realtime. The establishment I'm working on should have at least 500 active employees using the program at the same time which means a lot of stress to the suppose socket server I'm working.
The challenge is how to make the socket server thread-safe and at the same time fast. The socket sending issue has been resolve and I am now facing some "collections changed" problems due to multi-threading. I've implemented locking but that makes the program slow since it has to wait for certain threads to stop using the collections.
So if I create a new instance of the object like for example:
will it be better than doing this? :
I feel like I should really change how the code works or else I'll be dead -_-
Might be important info: the program has at least 50 packet handlers (which runs functions depending on the packetType received asynchronously).
The challenge is how to make the socket server thread-safe and at the same time fast. The socket sending issue has been resolve and I am now facing some "collections changed" problems due to multi-threading. I've implemented locking but that makes the program slow since it has to wait for certain threads to stop using the collections.
So if I create a new instance of the object like for example:
Code:
List<UserData> exclusiveUserDataList;
lock (UserDataList) {
exclusiveUserDataList = UserDataList.ToList();
}
foreach (var userData in exclusiveUserDataList) {
// Do Something
lock(UserDataList) UserDataList.Remove(userData);
}
Code:
lock (UserDataList) {
foreach (var userData in UserDataList) {
// Do Something
UserDataList.Remove(userData);
}
}
I feel like I should really change how the code works or else I'll be dead -_-
Might be important info: the program has at least 50 packet handlers (which runs functions depending on the packetType received asynchronously).