I need to call a non static method _methodY in another class _classX every time I execute Task.Factory.StartNew in class _classA. I don't want to instantiate a newclassXevery time. Is there a way where I can use the same instantiatedclassXwhenever I callTask.Factory.startNewfrom_classA`
Here is the code:
public void _classA
{
public void method
{
Task.Factory.StartNew(
() => _classX._methodY(),
token1,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
}
}
public void _classX()
{
public void _methodY()
{
}
}
I can't change classX nor _methodY to static. Do I need to implement singleton?