Answer the question
In order to leave comments, you need to log in
Confused about multithreading
Option one:
Task.Factory.StartNew(() =>
{
while (true)
{
Console.WriteLine("WTF");
Thread.Sleep(1000);
}
});
Console.ReadKey();
Console.WriteLine("Start");
Task.Factory.StartNew(() =>
{
while (true)
{
Console.WriteLine("WTF");
Thread.Sleep(1000);
}
});
Console.ReadKey();
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//Console.WriteLine("Start");
Task.Factory.StartNew(() =>
{
while (true)
{
Console.WriteLine("WTF");
Thread.Sleep(1000);
}
});
Console.ReadKey();
}
}
}
Answer the question
In order to leave comments, you need to log in
I copied your code, it works correctly, that is, it issues WTF once a second.
What do you compile?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question