コード例 #1
0
ファイル: FeedWorker.cs プロジェクト: zhangli0092/opennetcf
        private void WorkerProcess()
        {
            try
            {
                while (!stop)
                {
                    foreach (Uri destination in feedList)
                    {
                        receiveCallback(destination);
                    }
                    resetEvent.WaitOne(checkInterval, false);

                    //resetEvent.WaitOne();
                }
            }
            catch (Exception abortException)
            {
                Console.WriteLine((string)abortException.Message);
            }

//			catch (ThreadAbortException abortException)
//			{
//				Console.WriteLine((string)abortException.ExceptionState);
//			}
        }
コード例 #2
0
ファイル: Timer2.cs プロジェクト: zhangli0092/opennetcf
        private void ElapsedThreadProc()
        {
            while (true)
            {
                m_waitHandle.WaitOne();

                if (m_disposing)
                {
                    return;
                }

                ElapsedEventArgs eea = new ElapsedEventArgs(DateTime.Now);

                if (Elapsed != null)
                {
                    foreach (ElapsedEventHandler eeh in Elapsed.GetInvocationList())
                    {
                        // determine if we're supposed to Invoke or not
                        if (SynchronizingObject == null)
                        {
                            eeh(this, eea);
                        }
                        else
                        {
                            SynchronizingObject.Invoke(eeh, new object[] { this, eea });
                        }
                    }
                }
            }
        }
コード例 #3
0
        public static void PlayTone(Tone[] tones)
        {
            WAVEFORMAT_MIDI wfm = new WAVEFORMAT_MIDI();

            wfm.WAVEFORMATEX.FormatTag  = FormatTag.MIDI;
            wfm.WAVEFORMATEX.Channels   = 1;
            wfm.WAVEFORMATEX.BlockAlign = 8; // sizeof(WAVEFORMAT_MIDI_MESSAGE);
            wfm.WAVEFORMATEX.Size       = WAVEFORMAT_MIDI_EXTRASIZE;

            // trial & error seems to be the way to get this - tested using an Axim x51
            // maybe expose these if it varies from hardware to hardware
            wfm.USecPerQuarterNote  = 100000;
            wfm.TicksPerQuarterNote = 15;

            IntPtr          hWaveOut;
            EventWaitHandle hEvent = new EventWaitHandle(false, EventResetMode.ManualReset);

            byte[] d = wfm.GetBytes();

            int result = WaveAudio.NativeMethods.waveOutOpen(out hWaveOut, 0, d, hEvent.Handle, 0, CALLBACK_EVENT);

            Audio.CheckWaveError(result);

            WAVEFORMAT_MIDI_MESSAGE[] messages = new WAVEFORMAT_MIDI_MESSAGE[2 * tones.Length];
            int totalDuration = 0;

            for (int i = 0; i < tones.Length; i++)
            {
                messages[i * 2].DeltaTicks     = 0;
                messages[i * 2].MidiMsg        = (uint)(0x7F0090 | (tones[i].MIDINote << 8)); // Note on
                messages[i * 2 + 1].DeltaTicks = (uint)(tones[i].Duration);
                messages[i * 2 + 1].MidiMsg    = (uint)(0x7F0080 | (tones[i].MIDINote << 8)); // Note off

                totalDuration += tones[i].Duration;
            }

            byte[] headerData = new byte[messages.Length * WAVEFORMAT_MIDI_MESSAGE.Length];
            for (int i = 0; i < messages.Length; i++)
            {
                Buffer.BlockCopy(messages[i].GetBytes(), 0, headerData, i * WAVEFORMAT_MIDI_MESSAGE.Length, WAVEFORMAT_MIDI_MESSAGE.Length);
            }
            WaveHeader header = new WaveHeader(headerData);

            result = WaveAudio.NativeMethods.waveOutPrepareHeader(hWaveOut, header.Pointer, header.HeaderLength);
            Audio.CheckWaveError(result);

            result = WaveAudio.NativeMethods.waveOutWrite(hWaveOut, header.Pointer, header.HeaderLength);
            Audio.CheckWaveError(result);

            if (!hEvent.WaitOne(totalDuration * 20, false))
            {
                Debugger.Break();
            }

            result = WaveAudio.NativeMethods.waveOutUnprepareHeader(hWaveOut, header.Pointer, header.HeaderLength);
            Audio.CheckWaveError(result);

            result = WaveAudio.NativeMethods.waveOutClose(hWaveOut);
            Audio.CheckWaveError(result);
        }
コード例 #4
0
ファイル: Application2.cs プロジェクト: zhangli0092/opennetcf
        private static void RemoteActivateThreadProc()
        {
            EventWaitHandle wh = new EventWaitHandle(false, EventResetMode.AutoReset, Application2.StartupPath);

            while (true)
            {
                wh.WaitOne();

                currentFormFilter.ActivateCurrentForm();
            }
        }
コード例 #5
0
            public void StopListen()
            {
                bool            createdNew = false;
                EventWaitHandle ewh        = new EventWaitHandle(false, EventResetMode.ManualReset, WaitHandleName, out createdNew);

                if (ewh != null)
                {
                    m_quit = true;
                    ewh.Set();
                    EventWaitHandle quit = new EventWaitHandle(false, EventResetMode.ManualReset, WaitHandleNameQuit, out createdNew);
                    quit.WaitOne(5000, true);
                }

                m_listening = false;
            }