M
M
Morrowind2021-11-14 03:51:23
C++ / C#
Morrowind, 2021-11-14 03:51:23

How to apply a Property to a looped class during its asynchronous call?

Hello.

I have a class + an async method in the main loop from which I already call the class constructor.
I need to get a property of this class that is spinning there in while (true)
I understand that the problem is that I will not use await for the part of the code I need. But I don't quite understand how to use it.
I ask for advice, but rather an example.
Or do I want too much from asynchrony?

private static async Task<int> Run()
        {
            var x =  await Task.Run(() => new Base.Class1());
            var ex = x.ViewL.Count;
            Thread.Sleep(1000);
            return ex;
        }

        static void Main(string[] args)
        {
            var exit = Run();
             Thread.Sleep(7000);
            Console.WriteLine(exit);
            Console.Read();
        }


Class:

internal class Class1
    {
        List<string> list1;

        public Class1()
        {
            List<string> list228 = new List<string>();

            while (true)
            {
                list228.Add("meow");
                Thread.Sleep(1000);
                this.list1 = list228;
            }

        }

        public List<string> ViewL { get { return this.list1; } }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-11-14
@vabka

Is that not an option?

static async Task Main(string[] args)
        {
            var exit = await Run();
            Console.WriteLine(exit);
            Console.Read();
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question