从异步方法

时间:2015-08-17 21:48:44

标签: c# windows windows-phone-8 global-variables async-await

任何人都可以解释为什么我不能用异步方法设置全局变量的值?这是我的代码:

public static string sGlobalVar = "";

    public MainPage()
    {
        InitializeComponent();
        _AsyncCallMethod("string");
        MessageBox.Show(sGlobalVar);
    }

    public void _AsyncCallMethod(string sString)
    {
        _InetReadEx(sString);
    }


    public async void _myAsyncMethod(string sString)
    {
        try
        {
            //Do some magic coding here
            sGlobalVar = "Test text";
            //sGlobalVar value is not set after here
        }
        catch (Exception hre)
        {
            sGlobalVar = string.Empty;
        }

这是相同的样本,但这里的问题是;如何通过异步方法设置全局变量的值。

无论如何,我找到了解决方案。如果您想重新打开帖子,我可以编写解决方案。

谢谢。

0 个答案:

没有答案
相关问题