Windows Phone 7事件调用?

时间:2011-06-04 16:51:42

标签: c# windows-phone-7

我正在尝试使用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上运行吗?

由于

1 个答案:

答案 0 :(得分:5)

尝试使用:

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

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