yorimirus
yorimirus
CC#
Created by yorimirus on 3/30/2023 in #help
❔ Synchronise an object across two threads?
Alright, managed to implement it the correct way. That still didn't work but after some further investigation, it wasn't because of multithreading but some completely different code entirely. Despite that, thanks a lot for your help. I managed to learn something new today thanks to you.
36 replies
CC#
Created by yorimirus on 3/30/2023 in #help
❔ Synchronise an object across two threads?
yeah that's a good idea, no idea how I missed that
36 replies
CC#
Created by yorimirus on 3/30/2023 in #help
❔ Synchronise an object across two threads?
oh
36 replies
CC#
Created by yorimirus on 3/30/2023 in #help
❔ Synchronise an object across two threads?
Actually it seems like I won't need any timespans now. If the events themselves set the task as complete, then I just need to use Task.WhenAny(task, Task.Delay(timeout * 1000)) to make it automatically abort.
36 replies
CC#
Created by yorimirus on 3/30/2023 in #help
❔ Synchronise an object across two threads?
Okay I will go try it out, thanks a lot
36 replies
CC#
Created by yorimirus on 3/30/2023 in #help
❔ Synchronise an object across two threads?
I wonder why the MessageReceived event works fine though -_-
36 replies
CC#
Created by yorimirus on 3/30/2023 in #help
❔ Synchronise an object across two threads?
Yeah I have used SemaphoreSlim a few times before. Might be a good idea to completely rewrite this class tbh.
36 replies
CC#
Created by yorimirus on 3/30/2023 in #help
❔ Synchronise an object across two threads?
Never heard of this class, but sounds like the exact thing I need here
36 replies
CC#
Created by yorimirus on 3/30/2023 in #help
❔ Synchronise an object across two threads?
Ohh. So in the ConnectionLost event, I just set the TaskCompletionSource as completed?
36 replies
CC#
Created by yorimirus on 3/30/2023 in #help
❔ Synchronise an object across two threads?
What does a TaskCompletionSource do? I'm not quite sure what it does from the microsoft documentation.
36 replies
CC#
Created by yorimirus on 3/30/2023 in #help
❔ Synchronise an object across two threads?
TaskCompletionSource? Never heard of that. Will take a look at it. Thanks
36 replies
CC#
Created by yorimirus on 3/30/2023 in #help
❔ Synchronise an object across two threads?
that's what the _waitingForResponse field is for
36 replies
CC#
Created by yorimirus on 3/30/2023 in #help
❔ Synchronise an object across two threads?
yeah I throw an exception when that happens
36 replies
CC#
Created by yorimirus on 3/30/2023 in #help
❔ Synchronise an object across two threads?
Anything else I can do? I'm out of ideas. Thanks in advance.
36 replies
CC#
Created by yorimirus on 3/30/2023 in #help
❔ Synchronise an object across two threads?
The WaitForResponse methods are the ones where the thread continuously checks for a message. While the events get fired on a different thread, that manages the actual connection.
36 replies
CC#
Created by yorimirus on 3/30/2023 in #help
❔ Synchronise an object across two threads?
The TCPConnection is abstracted away to an interface because I have a specific way I communicate through this connection.
36 replies
CC#
Created by yorimirus on 3/30/2023 in #help
❔ Synchronise an object across two threads?
The weird thing is, the OnMessageReceived event is also run on a different thread than the one that actually waits, but this time, all the properties get properly set.
36 replies
CC#
Created by yorimirus on 3/30/2023 in #help
❔ Synchronise an object across two threads?
Here is the code:
36 replies