Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows Phone 7事件调用?_C#_Windows Phone 7 - Fatal编程技术网

C# Windows Phone 7事件调用?

C# Windows Phone 7事件调用?,c#,windows-phone-7,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

我正试图用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!");
    }));
}
那么,我是否可以为invoke找到另一种方法来使用WindowsPhone7

有没有其他方法可以让它在WP7上工作

谢谢

尝试使用:

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

        Dispatcher.BeginInvoke(() =>
        {
              MessageBox.Show("hello!");
        });
}
尝试使用:

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

        Dispatcher.BeginInvoke(() =>
        {
              MessageBox.Show("hello!");
        });
}
查看此博文:查看此博文:@Eric-No probs:)每当您要将数据从后台线程转移到UI线程(在WP7中)时,必须使用调度程序的BeginInvoke方法。@Eric-No probs:)每当您要将数据从后台线程转移到UI线程(在WP7中)您必须使用Dispatcher的BeginInvoke方法。