I'm trying to understand how to run callback functions in an async console application. My base console app code looks as follows:
using Nito.AsyncEx;
static void Main(string[] args)
{
AsyncContext.Run(() => MainAsync());
}
static async Task MainAsync()
{
}
The method that I want to run in Async mode is the following from a websocket api:
using ExchangeSharp;
public static void Main(string[] args)
{
// create a web socket connection to Binance. Note you can Dispose the socket anytime to shut it down.
// the web socket will handle disconnects and attempt to re-connect automatically.
ExchangeBinanceAPI b = new ExchangeBinanceAPI();
using (var socket = b.GetTickersWebSocket((tickers) =>
{
Console.WriteLine("{0} tickers, first: {1}", tickers.Count, tickers.First());
}))
{
Console.WriteLine("Press ENTER to shutdown.");
Console.ReadLine();
}
}
The above code is meant to lock a console app and subscribe to an event which receives data, and to do something with the received data.
What I want to do is run the above in a separate thread or in async so that I can continue with my code in the MainAsync() function.
My C# experience with this is limited. Will appreciate any help!