Errors with Methods and Classes ( Threading )
C# 4.0 using SharpDevelop
These are the errors I get with the following program.
in Program.cs Line 21 Error = Argument1:cannot convert from 'void' to 'System.Action' (CS1503)
in Program.cs Line 21 Error = The best overloaded method match for 'voidoverrideproblem.ThreadClass1.SeparateThread(System.Action)' has some invalid arguments (CS1502)
Its three files. Each one is named with the source code to it.
Uncomment ( // ) one of the two choices in the Program.cs file to see the problem. One works, the other does not. The one that does not work is the one I need to solve the answer too.
I just cannot seem to figure out how to solve this so that it works. Anyone have any ideas on this ?
// Program.cs
using System;
namespace voidoverrideproblem
{
class Program
{
public static void Main(string[] args)
{
string thenumber = "25565";
DisplayTheNumber runnumber = new DisplayTheNumber();
ThreadClass1 startthread = new ThreadClass1();
// Choice 1 here works.
// runnumber.DisplayNumber(thenumber);
// Choice 2 does not.
startthread.SeparateThread(runnumber.DisplayNumber(thenumber));
Console.Write("Hit any key to exit.");
Console.ReadKey();
}
}
}
// ThreadClass1.cs
using System;
using System.Threading;
namespace voidoverrideproblem
{
public class ThreadClass1
{
public void SeparateThread(Action action)
{
var thread = new Thread(new ThreadStart(action));
thread.Start();
}
}
}
// MainMenu.cs
using System;
namespace voidoverrideproblem
{
public class DisplayTheNumber
{
public void DisplayNumber(string thenumber)
{
Console.WriteLine("The current port is : " + thenumber);
}
}
}