I’m working on my little chess engine in C#, and I want to make my search function run in the background. (so that the UI is still interactable) I checked some other stackoverflow solutions talking about the async
and await
keywords (also about Task.Run()
). But I’m at the beginner level. I could not understand what was going on, and I could not make it work for my code.
Here’s my sample code:
public static Move GetMove()
{
// This function is called every frame if it is the engine's turn
// Your solution goes here
}
engine.StartSearch()
function starts a search, and it will probably take some time to finish. You can grab the result(Move) by calling engine.GetMove()
after a search.
How can I make a background task for the search, and how do I make it wait for the result?
I have tried using async and await keywords but I don’t understand how it works..
2