| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2877 人关注过本帖
标题:application.run(new form1(0)异常,谁帮我看下好吗?
只看楼主 加入收藏
a317060944
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-5-4
收藏
 问题点数:0 回复次数:3 
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();
        }















    }
}
搜索更多相关主题的帖子: using System application run new 
2008-05-04 17:44
a317060944
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-5-4
收藏
得分:0 
提示说找不到文件,怎么回事
2008-05-04 17:45
andey
Rank: 2
等 级:新手上路
威 望:4
帖 子:938
专家分:0
注 册:2007-7-18
收藏
得分:0 
application.run(new Form)是在Program里...你贴出来的是什么啊?

msdn == 葵花宝典!!!
QQ:122768959
2008-05-05 10:13
梦心
Rank: 4
来 自:福建平和
等 级:贵宾
威 望:13
帖 子:1910
专家分:0
注 册:2007-5-11
收藏
得分:0 
application.run(new Form1()) ,写在Program里

我清高和我骄傲的倔强,在风中大声的唱:我不听,我不听~~做我自己最特别,呼呼~~啦啦~~~
我的博客园地址: [url]http://[/url]
2008-05-05 10:44
快速回复:application.run(new form1(0)异常,谁帮我看下好吗?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030326 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved