application.run(new form1(0)异常,谁帮我看下好吗?
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using
using
using
using System.Media;
using System.Audio;
using System.Threading;
namespace cc
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int second = 0;
private bool _isconnecting;
public static string theResponse = "";
public byte[] buffer = new byte[65535];
private WaveInDevice _wavein;
private Thread _receiver;
private WaveOutDevice _waveout;
private ACMStream _decodec;
private ACMStream _encodec;
private Socket _socket;
public static IPAddress hostip = IPAddress.Parse("210.43.136.102");
public IPEndPoint server = new IPEndPoint(hostip, port);
//public IPEndPoint _toip;
// private WaveLib.WaveInRecorder m_Recorder;
// private WaveLib.WaveOutPlayer m_Player;
// private WaveLib.FifoStream m_Fifo = new WaveLib.FifoStream();
//private byte[] m_RecBuffer;
// private byte[] m_PlayBuffer;
// private static ManualResetEvent connectDone =
// new ManualResetEvent(false);
// private static ManualResetEvent sendDone =
// new ManualResetEvent(false);
// private static ManualResetEvent receiveDone =
// new ManualResetEvent(false);
private const int port = 8330;
// private static String response = String.Empty;
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text != "cc" || textBox2.Text != "yayaya")
{
MessageBox.Show("用户名或者密码错误!", "警告");
textBox1.Focus();
textBox1.Text = "";
textBox2.Text = "";
}
else
{
label1.Visible = false;
label2.Visible = false;
textBox1.Visible = false;
textBox2.Visible = false;
button1.Visible = false;
button2.Visible = false;
linkLabel1.Visible = false;
pictureBox2.Visible = true;
label5.Visible = true;
label6.Visible = true;
timer1.Enabled = true;
timer1.Interval = 1000;
second = Convert.ToInt32(label6.Text);
}
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void label5_Click(object sender, EventArgs e)
{
pictureBox2.Visible = false;
label5.Visible = false;
label6.Visible = false;
label1.Visible = true;
label2.Visible = true;
textBox1.Visible = true;
textBox1.Text = "";
textBox2.Visible = true;
textBox2.Text = "";
button1.Visible = true;
button2.Visible = true;
linkLabel1.Visible = true;
timer1.Stop();
textBox1.Focus();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (second >= 0)
{
label6.Text = second.ToString();
second--;
if (second == 0)
{
pictureBox2.Visible = false;
label5.Visible = false;
label6.Visible = false;
label7.Visible = true;
listBox1.Visible = true;
label3.Visible = true;
label4.Visible = true;
statusStrip1.Visible = true;
button3.Visible = true;
}
}
}
public void label3_Click(object sender, EventArgs e)
{
WaveFormat format1 = new WaveFormat();
format1.FormatTag = 1;
format1.Channels = 1;
format1.BitsPerSample = 16;
format1.SamplesPerSec = 8000;
format1.AvgBytesPerSec = 16000;
format1.BlockAlign = 2;
format1.ExtraData = new byte[0];
WaveFormat format2 = new WaveFormat();
format2.FormatTag = 34;
format2.Channels = 1;
format2.BitsPerSample = 1;
format2.SamplesPerSec = 8000;
format2.AvgBytesPerSec = 1067;
format2.BlockAlign = 32;
format2.ExtraData = new byte[32];
format2.ExtraData[0] = 1;
format2.ExtraData[2] = 0xF0;
_wavein = new WaveInDevice(format1);
_wavein.Recorded += new WaveDataEventHandler(Recorded);
_wavein.Open();
_waveout = new WaveOutDevice(format1);
_waveout.Open();
_encodec = new ACMStream(format1, format2);
_encodec.Open();
_decodec = new ACMStream(format2, format1);
_decodec.Open();
_socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
_socket.BeginConnect(server,
new AsyncCallback(ConnectCallback), _socket);
_wavein.Start();
_receiver = new Thread(new ThreadStart(this.Run));
_receiver.Start();
_isconnecting = false;
}
private static void ConnectCallback(IAsyncResult ar)
{
try
{
// Retrieve the socket from the state object.
Socket client = (Socket)ar.AsyncState;
// Complete the connection.
client.EndConnect(ar);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
private void Recorded(object sender, WaveData data)
{
try
{
WaveData dedata = _encodec.Convert(data);
_socket.SendTo(dedata.Data, server);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
private void Run()
{
while (true)
{
EndPoint frm = (EndPoint)server;
try
{
int len = _socket.ReceiveFrom(buffer, ref frm);
WaveData dedata = new WaveData(len);
dedata.BytesUsed = (uint)len;
dedata.Flags = 0;
dedata.Loops = 0;
dedata.User = 0;
Array.Copy(buffer, 0, dedata.Data, 0, len);
WaveData data = _decodec.Convert(dedata);
_waveout.Play(data);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
private void button3_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}