I get OutOfMemoryException when I call this method on startup. StartSignalR method should run a Task which calls Update() method every second.
public void StartSignalR()
{
Task t = Task.Run(() =>
{
try
{
bool push = true;
while (push)
{
Update();
}
}
catch (System.Exception ex)
{
LogManager.LogError(ex);
}
});
}
I use Task.Delay in Update()
private async static void Update()
{
await Task.Delay(1000);
Updater.MPrice();
}
Task.Runmost certainly doesn't cause an OOM exception. You need to look at and debug your code, you have a memory leak somewhereUpdate()probably millions of times per second, so whatever is insideUpdater.MPrice()is leaking memory somewhere, or creating objects big enough to make your system run out of memory. You need toawaitthe call toUpdateMPrice.awaitonUpdate, andUpdateshould probably returnTasknotvoid.