Exemplo n.º 1
0
 /// <summary>
 /// Stops feed retreival process.
 /// </summary>
 public void Stop()
 {
     try
     {
         this.stop = true;
         timer.Change(Timeout.Infinite, Timeout.Infinite);
         resetEvent.Set();
         //thread.Abort();
         //thread.Join();
         started = false;
     }
     catch { };
 }
Exemplo n.º 2
0
        /// <summary>
        /// Begins running a standard application message loop on the current thread, and makes the specified form visible.
        /// </summary>
        /// <param name="mainForm">Form on which main message loop runs</param>
        /// <param name="runAsSingletonApp">When <b>true</b>, if an existing instance of the app is already running, the current application instance will simply exit and the already running app will come to the fore</param>
        /// <param name="displayMainForm">When set to true, the main form will be automatically displayed, else the app will be responsible for showing the Form</param>
        public static void Run(Form mainForm, bool runAsSingletonApp, bool displayMainForm)
        {
            bool isNew = true;

            NamedMutex m = new NamedMutex(true, Application2.StartupPath, out isNew);

            if (runAsSingletonApp)
            {
                if (!isNew)
                {
                    // activate the existing instance
                    EventWaitHandle wh = new EventWaitHandle(false, EventResetMode.AutoReset, Application2.StartupPath);
                    wh.Set();
                    return;
                }
                else
                {
                    //create a thread to wait for any subsequent instances to signal
                    remoteActivateThread = new Thread(new System.Threading.ThreadStart(RemoteActivateThreadProc));
                    remoteActivateThread.IsBackground = true;
                    remoteActivateThread.Name         = "SDF Application2 UI thread";
                    remoteActivateThread.Start();

                    // create a filter to track the currently active form so if
                    // we get reactivated from another instance attempting to run
                    // we know what Form to put topmost
                    currentFormFilter = new CurrentFormMessageFilter();
                    AddMessageFilter(currentFormFilter);
                }
            } // if (runAsSingletonApp)

            mainForm.Closed      += new EventHandler(MainFormExit);
            Application2.mainForm = mainForm;
            RunMessageLoop(displayMainForm);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This member overrides Component.Dispose.
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                GC.SuppressFinalize(this);
            }

            if (m_running)
            {
                Stop();
            }

            if (m_callbackHandle.IsAllocated)
            {
                m_callbackHandle.Free();
            }

            // stop worker thread
            m_disposing = true;
            m_waitHandle.Set();

            m_waitHandle.Close();

            base.Dispose(disposing);
        }
Exemplo n.º 4
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;
            }
Exemplo n.º 5
0
 protected void Dispose(bool finalizing)
 {
     // Check to see if Dispose has already been called.
     if (!this.disposed)
     {
         // kill the worker thread
         m_quit = true;
         EventWaitHandle ewh = new EventWaitHandle(false, EventResetMode.ManualReset, WaitHandleName);
         ewh.Set();
     }
     if (!finalizing)
     {
         GC.SuppressFinalize(this);
     }
     disposed = true;
 }
Exemplo n.º 6
0
        /// <summary>
        /// When overridden in a derived class, releases the unmanaged resources used by the LargeIntervalTimer, and optionally releases the managed resources.
        /// </summary>
        public void Dispose()
        {
            lock (m_interlock)
            {
                m_disposing = true;

                if (Enabled)
                {
                    Enabled = false;
                }

                if (m_quitHandle != null)
                {
                    m_quitHandle.Set();
                    m_quitHandle.Close();
                    m_quitHandle = null;
                }
            }
        }
Exemplo n.º 7
0
            private unsafe void ThreadProc()
            {
                IntPtr notifyHandle = NativeMethods.FindFirstChangeNotification(m_path, true, filter);
                FileNotifyInformation notifyData = new FileNotifyInformation();
                uint returned  = 0;
                uint available = 0;

                EventWaitHandle ewh            = new EventWaitHandle(false, EventResetMode.ManualReset, WaitHandleName);
                EventWaitHandle quitWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset, WaitHandleNameQuit);

                while (!m_quit)
                {
                    ewh.Reset();

                    if (EventWaitHandle.WaitAny(new IntPtr[] { notifyHandle, ewh.Handle }, TimeoutInfinite, false) != EventWaitHandle.WaitTimeout)
                    {
                        if (m_quit)
                        {
                            break;
                        }

                        IntPtr ptr = IntPtr.Zero;
                        if (NativeMethods.CeGetFileNotificationInfo(notifyHandle, 0, ref ptr, 0, ref returned, ref available))
                        {
                            if (available > 0)
                            {
                                int maxData = 2048;
                                fixed(byte *pData = new byte[maxData])
                                {
                                    // get data
                                    if (NativeMethods.CeGetFileNotificationInfo(notifyHandle, 0, pData, maxData, ref returned, ref available))
                                    {
                                        notifyData = new FileNotifyInformation(pData, 0);

                                        // handle data in notifyData
                                        if (ValidateByFilter(notifyData.Filename))
                                        {
                                            RaiseEvents(notifyData.Action, notifyData.Filename);
                                        }

                                        int offset = 0;
                                        offset += notifyData.NextEntryOffset;

                                        while (notifyData.NextEntryOffset > 0)
                                        {
                                            notifyData = new FileNotifyInformation(pData, offset);

                                            if (ValidateByFilter(notifyData.Filename))
                                            {
                                                RaiseEvents(notifyData.Action, notifyData.Filename);
                                            }
                                            offset += notifyData.NextEntryOffset;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                //Seems that subdirectories don't return anything but then the notifyHandle is never reset and if available data is 0 notifyHandle never resets
                                NativeMethods.FindCloseChangeNotification(notifyHandle);
                                notifyHandle = NativeMethods.FindFirstChangeNotification(m_path, true, filter);
                            }
                        }
                    } // if( waithandle...
                }     // while (!m_quit)

                NativeMethods.FindCloseChangeNotification(notifyHandle);
                quitWaitHandle.Set();
            }