There is a factory method that returns an X object on call. The object X itself , which is formed on request, accepts input parameters, and in the constructor it runs the method method
, after which the object X is returned will be returned.
It is necessary to make the object X “built” in a given amount of time (for example, 20 seconds).
You can do this with thread.sleep
. However, it will not look very correct. It is also possible to make a timer and a while(flag)
, where the flag will become false
after timer tick . However, I would like to achieve the necessary work only through the use of a timer. However, with such an architecture, when you start the timer and subscribe to it, the method method
(which starts from the constructor and sets up object X ) will be completed immediately, and there will be no waiting.
Will the question be solved if the method is run not from the constructor, but after the object is created?
What is the best way to implement suspending a particular method?
Thread.Sleep
incorrect? Do you have any additional requirements that you do not voice? - VladDmethod
really takes 20 seconds, then why not just execute it synchronously? Or do you get data from another stream from somewhere? Your problem looks strange, probably, you are not telling something. - VladD