Make function wait for variable to be generated

0

I have the following code:

XmlParaApi = xml;

which passes a string variable (xml) to a global string variable (XmlParaApi). Until then all this code is in an Api, since my problem is with the code below:

 string XmlApi = XmlApi.XmlParaApi;

The problem occurs because I have two functions occur simultaneously, but I need the second code to wait for the variable (XmlParaApi) to be ready to be used, I have seen that there is a way to do it for "wait", but I can not can someone help?

    
asked by anonymous 20.03.2017 / 17:54

1 answer

0

Where you should expect, you can use a while ...

ex:

    While (String.IsNullOrEmpty(XmlApi))
    {
        System.Threading.Thread.Sleep(500);
    }

obs. I'm considering that the variable will be populated in another thread, and that will always be populated. Otherwise, put some triggers to exit the while for example, after 100 attempts, so that the application does not get caught in this command.

    
20.03.2017 / 19:59