Keyinator
Keyinator
CC#
Created by The king of kings on 4/25/2023 in #help
❔ Breaking an infinite while loop
must be created outside the while loop so the condition can be checked. Then updated inside
60 replies
CC#
Created by Keyinator on 4/25/2023 in #help
❔ Using JsonConvert to send over interface
This is code for a gameserver which has multiple modes. Depending on the mode the player is in it functions will perform differently. I have a Property current_mode which is used for all of that. Now depending on the underlying class that current_mode is, the functions will perform differently. So now to put that information from the server to the client, I wanted to send it via the method above.
8 replies
CC#
Created by Keyinator on 9/26/2022 in #help
Threading Return to old thread
28 replies
CC#
Created by Keyinator on 9/26/2022 in #help
Threading Return to old thread
Alright. I'll implement that and see where it gets me :)
28 replies
CC#
Created by Keyinator on 9/26/2022 in #help
Threading Return to old thread
(?)
28 replies
CC#
Created by Keyinator on 9/26/2022 in #help
Threading Return to old thread
So I would insert a touple with Func<T> and a TaskCompletionSource<T> In the worker I would evaluate Func and set the result for the source.
28 replies
CC#
Created by Keyinator on 9/26/2022 in #help
Threading Return to old thread
Ahh. That sounds implementable
28 replies
CC#
Created by Keyinator on 9/26/2022 in #help
Threading Return to old thread
It could work with that but there'd have to be some way of retrieving the evaluation after it's done.
28 replies
CC#
Created by Keyinator on 9/26/2022 in #help
Threading Return to old thread
I have to rephrase myself. It does not have to return to the original background thread but it should not stay on the main thread because then all following code will be run on the main thread subsequently putting a lot of load on it. My goal of this function / helper was to translate example code that would look like this:
[...]
DoWorkOnBackGround()
await Delay(0) //<-- This is the method that changes the thread to main thread
var x = DoWorkOnForeGroundAndRetrieveResult()
await Task.Run(async() => {
DoFurtherWorkOnBackGround(x)
}
[...]
DoWorkOnBackGround()
await Delay(0) //<-- This is the method that changes the thread to main thread
var x = DoWorkOnForeGroundAndRetrieveResult()
await Task.Run(async() => {
DoFurtherWorkOnBackGround(x)
}
[...]
DoWorkOnBackGround()
var x = await ThreadinHelper.RetrieveOnForeGround(() => {
return DoWorkOnForeGroundAndRetrieveResult();
}
DoFurtherWorkOnBackGround(x)
[...]
DoWorkOnBackGround()
var x = await ThreadinHelper.RetrieveOnForeGround(() => {
return DoWorkOnForeGroundAndRetrieveResult();
}
DoFurtherWorkOnBackGround(x)
Because in the first example when you need to go to the main thread more frequently you're going to nest more and more Task.Runs
28 replies
CC#
Created by Keyinator on 9/26/2022 in #help
Threading Return to old thread
The problem is that I need a result back. It's not an Action but a Func<T>
28 replies
CC#
Created by Keyinator on 9/26/2022 in #help
Threading Return to old thread
Basically the !server!-side code isn't multi-threading friendly and thus you often need to go to the main thread to execute some code. This helper is supposed to do the following: If already on main thread, execute the code If not: - go to main thread - execute the function - return to original (background) thread (in order to not put too much load on the main thread)
28 replies