Question

I have tried using system.threading.task.task.factor.startnew but it still pauses the whole thing.

using System;

namespace test
{
class MainClass
{
    public static void test2 ()
    {
        System.Threading.Thread.Sleep(500);
        Console.WriteLine("Test");
    }

    public static void Update ()
    {
        System.Threading.Thread.Sleep(1);
        Console.WriteLine("testt");
    }


    public static void Main ()
    {
        while (true) {
            System.Threading.Tasks.Task.Factory.StartNew (() => test2 ());
            System.Threading.Tasks.Task.Factory.StartNew (() => Update ());
        }
    }

}

}

What am I doing wrong?

Was it helpful?

Solution

You need to use two threads

 class MainClass
    {
        public static void Main()
        {
            Task.Factory.StartNew(MainClass.test2);
            Task.Factory.StartNew(MainClass.Update);

            Console.ReadLine();
        }

        public static void test2()
        {
            while (true)
            {
                System.Threading.Thread.Sleep(500);
                Console.WriteLine("Test");

            }
        }

        public static void Update()
        {
            while (true)
            {
                Console.WriteLine("Hello");
                System.Threading.Thread.Sleep(250);
            }


        }

    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top