Windows Phone 7的事件调用?(Windows Phone 7 Event Invoke

2019-09-28 03:46发布

我试图处理与Visual Studio的C#的事件,如我与我的Windows窗体一样,因此,例如:

在我的Windows Phone 7我的代码如下所示:

//ASDF.CS CLASS  

public delegate void SignedOn(string Screenname);

public event SignedOn SO;

public void dataIncoming(string packet)
{
     switch (packet)
 {
    case 0:
        if (SO != null)
                                    SO(m_Screenname);
        break;
}
}

//MainWindow.xaml.cs

m_A.SignedOn += new ASDF.SignedOn(m_A_LoggedIn);


void m_OSC_LoggedIn(string Screenname, string FormattedSN, string Email)
    {
        //Works all the way to this sub then the code in here don't get ran because there is no invoke with WP7

        MessageBox.Show("hello!");
}

我的Windows窗体的代码看起来像这样的工作:

//ASDF.CS CLASS  

public delegate void SignedOn(string Screenname);

public event SignedOn SO;

public void dataIncoming(string packet)
{
     switch (packet)
 {
    case 0:
        if (SO != null)
                                    SO(m_Screenname);
        break;
}
}

//MainWindow.cs

m_A.SignedOn += new ASDF.SignedOn(m_A_LoggedIn);


void m_OSC_LoggedIn(string Screenname, string FormattedSN, string Email)
    {
         this.Invoke(new MethodInvoker(delegate
        {
            MessageBox.Show("hello!");
    }));
}

那么,有没有反正我可以得到一个另类的调用与Windows Phone 7的工作?

有没有得到这对WP7的任何其他工作方式?

谢谢

Answer 1:

尝试使用:

void m_OSC_LoggedIn(string Screenname, string FormattedSN, string Email)
{

        Dispatcher.BeginInvoke(() =>
        {
              MessageBox.Show("hello!");
        });
}


文章来源: Windows Phone 7 Event Invoke?