Mobility SDK - Receiving multiple events.

Mobility SDK - Receiving multiple events.

Hello-

I am currently evaluating the Mobility SDK for a couple projects. The problem that I am having is with receiving multiple events. I am using W2K with a C# and the app is a windows form application. I am trying to pop open a form when a network comes into range. And it works, once. All repeated events are not triggered. What did I miss? Any help is appreciated. Thanks in advance.

Rob

Here is the details of the C# app I am working with:

public class Form1 : System.Windows.Forms.Form
{
private LinkProtocolClass linkproto;
private LinkProtocolInstance lpinstance;
private Form1.NetworkObserver networkobserver;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//

NetworkObserver networkobserver = new Form1.NetworkObserver();

}

private void Form1_Load(object sender, System.EventArgs e)
{
linkproto = new LinkProtocolClass();
LinkProtocolCollection lpcollection = (LinkProtocolCollection) linkproto.GetInstances();
if ( !lpcollection.HasNext() )
{
MessageBox.Show("Computer has no network interface!","Network Interface Error",MessageBoxButtons.OK, MessageBoxIcon.Error);
}
while ( lpcollection.HasNext())
{
lpinstance = (LinkProtocolInstance) lpcollection.Next();
string type = lpinstance.GetType();
networkobserver = new NetworkObserver();

if( type.Equals("Protocol802_11"))
{
if (lpinstance.Enabled.GetValue() == true )
{
&n
bsp; lpinstance.MediaConnected.AddObserver(networkobserver);
lpinstance.MediaDisconnected.AddObserver(networkobserver);
}
}
}
}
internal class NetworkObserver : Observer
{
public NetworkObserver()
{
//
// TODO: Add constructor logic here
//
}

public override void Notify(Event e)
{
if ( e.GetType() == EventBase.EventType.eMediaConnected )
{
NetworkInRange();
}
}
public static void NetworkInRange()
{
Update updateForm = new Update();
updateForm.ShowDialog();
}

///
/// The main entry point for the application.
///
[MTAThread]
static void Main()
{
Application.Run(new Form1());
}

4 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项

Dear Rob,

Thanks for your interest in the Mobile Platform SDK.

To catch your problem, please provide the detailed explanation of the trouble you are having and answer the following questions:

Which version of the SDK do you use:

Which application/projectare youadopting to test the IMPSDK:

List each step that was taken to receive the error:

Resulting error from taking the above steps:

Other explanatory information:

And we'd like to know whether you have the same problem on the WinXP system.

If you can't input all your code here, you can send your samples/applications to us via: IMPSDK_support@intel.comor submit issue in Http://premier.intel.com

Thanks,

Yang

I wasn't able to get the code above to work for me (it wouldn't compile) so I reworked it as the following which seems to work. Please try this and see if it works for you as well.

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using Intel.Mobile.Base;

using Intel.Mobile.Context;

using Intel.Mobile.Network;

namespace FormsLinkProtocolConnectDisconnectTest

{

///

/// Summary description for Form1.

///

public class Form1 : System.Windows.Forms.Form

{

private LinkProtocolClass linkproto;

private LinkProtocolInstance lpinstance;

private Form1.NetworkObserver networkobserver;

///

/// Required designer variable.

///

private System.ComponentModel.Container components = null;

public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

NetworkObserver networkobserver = new Form1.NetworkObserver();

}

///

/// Clean up any resources being used.

///

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

///

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

///

private void InitializeComponent()

{

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(292, 266);

this.Name = "Form1";

this.Text = "Form1";

this.Load += new System.EventHandler(this.Form1_Load);

}

#endregion

private void Form1_Load(object sender, System.EventArgs e)

{

linkproto = new LinkProtocolClass();

LinkProtocolCollection lpcollection = (LinkProtocolCollection) linkproto.GetInstances();

if ( !lpcollection.HasNext() )

{

MessageBox.Show("Computer has no network interface!","Network Interface Error",MessageBoxButtons.OK, MessageBoxIcon.Error);

}

else

{

while ( lpcollection.HasNext())

{

lpinstance = (LinkProtocolInstance) lpcollection.Next();

string type = lpinstance.GetType();

networkobserver = new NetworkObserver();

if( type.Equals("Protocol802_11"))

{

if (lpinstance.Enabled.GetValue() == true )

{

lpinstance.MediaConnected.AddObserver(networkobserver);

lpinstance.MediaDisconnected.AddObserver(networkobserver);

break;

}

}

}

}

}

///

/// The main entry point for the application.

///

[MTAThread]

static void Main()

{

Application.Run(new Form1());

}

internal class NetworkObserver : Observer

{

public NetworkObserver()

{

}

public override void Notify(Event e)

{

if ( e.GetType() == EventBase.EventType.eMediaConnected )

{

System.Diagnostics.Debug.WriteLine("802.11 network adapter connected!");

}

if ( e.GetType() == EventBase.EventType.eMediaDisconnected )

{

System.Diagnostics.Debug.WriteLine("802.11 network adapter disconnected");

}

}

}

}

}

...or here it is as a file attachement.

Thanks,
Lester

附件: 

附件尺寸
下载 Form1.cs3.21 KB

发表评论

登录添加评论。还不是成员?立即加入