Решение:

public static int outputResult = 10;
public static int functionParameter = 20;

public void Main()
{
outputResult = 1;
Thread newThread = new Thread(new ThreadStart(TestMethod));
newThread.Start();

long duration = 3000;
var sw = new Stopwatch();
sw.Start();
while (true)
{
if (sw.ElapsedMilliseconds > duration) {
sw.Stop(); break;
}
}
newThread.Abort("Information from Main.");
// Wait for the thread to terminate.
newThread.Join();
}

static void TestMethod()
{
try
{
outputResult = functionParameter + 1000;
while (true)
{
Console.WriteLine("New thread running.");
Thread.Sleep(1000);
break;
}
}
catch (ThreadAbortException abortException)
{
Console.WriteLine((string)abortException.ExceptionState);
}

 

Опубликовано в ASP.NET