不能调用委托
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.NetworkInformation;
using System.Media;
namespace 监视网络连接
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private SoundPlayer MyPlayer = new SoundPlayer();
private Microsoft.VisualBasic.Devices.ServerComputer My = new Microsoft.VisualBasic.Devices.ServerComputer();
private void Form1_Load(object sender, EventArgs e)
{
NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(AvailabilityChangedCallback);
MyPlayer.SoundLocation = "BEEP2.WAV ";
MyPlayer.LoadAsync();
MyPlayer.Play();
}
static void AvailabilityChangedCallback(object sender, EventArgs e)
{
SoundPlayer MyPlayer = new SoundPlayer();
Microsoft.VisualBasic.Devices.ServerComputer My = new Microsoft.VisualBasic.Devices.ServerComputer();
if (!My.Network.IsAvailable)
{
MessageBox.Show( "网络连接失败! ", "信息提示 ", MessageBoxButtons.OK, MessageBoxIcon.Information);
MyPlayer.SoundLocation = "ALARM8.WAV ";
MyPlayer.LoadAsync();
MyPlayer.Play();
}
else