-1

I'am making an application in C# .Net 4.5. I am trying to use multithreading, via tasks. I have an array of tasks that I get to run some process. I want the task to return a enumeration which is called enumSignal. However I do not know what to do, the below code is my attempt.

It highlights the line "_taskFactory.StartNew(_indicator[I].Run)" with the message The call is ambiguous between the following methods.

 public void RunIndicators()
        {
            _taskFactory = new TaskFactory();

            Task<enumSignal>[] taskIndicator = new Task<enumSignal>[_indicator.Length];

            for (int i = 0; i < taskIndicator.Length; i++)
            {

                taskIndicator[i] = _taskFactory.StartNew(_indicator[i].Run);

            }
            Task.WaitAll(taskIndicator);
        }
mHelpMe
  • 6,336
  • 24
  • 75
  • 150

1 Answers1

0

The C# compiler can't always infer generic delegate types when multiple overloads exist. Try adjusting your StartNew() call as follows:

_taskFactory.StartNew((Func<enumSignal>)_indicator[i].Run)

...or, if you prefer:

_taskFactory.StartNew<enumSignal>(_indicator[i].Run)

This assumes _indicator[i].Run() has no arguments and returns an enumSignal.

Mike Strobel
  • 25,075
  • 57
  • 69