Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

NAUDIO.dll C# event handler issue

  1. May 4, 2014 #1
    This is one of the many code samples i've tried for NAUDIO,but on all of them they say that += new EventHandler<StoppedEventArgs> is incorrect. There is no other issue. Anybody know whats happening?

    Code (Text):

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using NAudio;
    using System.Windows.Forms;
    using NAudio.Wave;
    using NAudio.Utils;
    using NAudio.Mixer;
    using NAudio.Midi;

    using System.Timers;

    namespace WindowsFormsApplication4
        public partial class Form1 : Form
            public Form1()

             public WaveIn waveSource = null;
        public WaveFileWriter waveFile = null;
        public string RECORDING_PATH;

        public void AudioRecorder(string fileName)
            RECORDING_PATH = fileName;

        public void Start()
            waveSource = new WaveIn();
            waveSource.WaveFormat = new WaveFormat(44100, 1);
            waveSource.DeviceNumber = 0;
            waveSource.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);
            waveSource.RecordingStopped += new EventHandler<StoppedEventArgs>(waveSource_RecordingStopped);

            waveFile = new WaveFileWriter(RECORDING_PATH, waveSource.WaveFormat);

            System.Timers.Timer t = new System.Timers.Timer(30000);

            t.Elapsed += new ElapsedEventHandler(Stop);




        private void Stop(object sender, ElapsedEventArgs args)

        private void waveSource_DataAvailable(object sender, WaveInEventArgs e)
            if (waveFile != null)
                waveFile.WriteData(e.Buffer, 0, e.BytesRecorded);

        private void waveSource_RecordingStopped(object sender, StoppedEventArgs e)
            if (waveSource != null)
                waveSource = null;

            if (waveFile != null)
                waveFile = null;


  2. jcsd
  3. May 4, 2014 #2


    Staff: Mentor

    You aren't coding this as a console application, are you?

    Some more information would be helpful, such as the version of NAudio you're using, and a detailed description of the error you're seeing.
  4. May 4, 2014 #3


    User Avatar
    Gold Member

    Are you getting this error at runtime or compile time? It compiles fine for me.
  5. May 5, 2014 #4
    I think I just had an incompatible version because I referenced the DLL from one of my other projects and it works fine. Thanks anyways, apologies for the inconveniance.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: NAUDIO.dll C# event handler issue
  1. Weird C++ Array Issue (Replies: 15)

  2. Issues with C++ errors? (Replies: 13)