private void ThreadProc()
        {
            bool fAbort = false;

            try
            {
                m_dev.OnProgress += new MFDevice.OnProgressHandler(OnStatus);

                if (m_evtShutdown.WaitOne(0, false))
                {
                    return;
                }

                m_evtDevice = m_dev.EventCancel;

                bool fMicroBooter = (m_dev.Ping() == PingConnectionType.MicroBooter);

                if (!fMicroBooter)
                {
                    m_dev.DbgEngine.PauseExecution();
                }

                if (m_fEraseCmd)
                {
                    if (!m_dev.Erase(m_eraseBlocks))
                    {
                        throw new MFDeployEraseFailureException();
                    }
                }
                else
                {
                    int cnt = 0;

                    List <uint> executionPoints = new List <uint>();

                    foreach (string file in m_files)
                    {
                        uint entry = 0;

                        if (Path.GetExtension(file).ToLower() == ".nmf")
                        {
                            if (!m_dev.DeployUpdate(file))
                            {
                                throw new MFDeployDeployFailureException();
                            }

                            return;
                        }
                        else if (!m_dev.Deploy(file, m_sigFiles[cnt++], ref entry))
                        {
                            throw new MFDeployDeployFailureException();
                        }

                        if (entry != 0)
                        {
                            executionPoints.Add(entry);
                        }
                    }

                    executionPoints.Add(0);

                    if (!fMicroBooter)
                    {
                        for (int i = 0; i < 10; i++)
                        {
                            if (m_dev.Connect(500, true))
                            {
                                break;
                            }
                        }
                    }
                    OnStatus(100, 100, "Executing Application");
                    foreach (uint addr in executionPoints)
                    {
                        if (m_dev.Execute(addr))
                        {
                            break;
                        }
                    }
                }

                //if (!m_dev.CheckForMicroBooter() && m_dev.DbgEngine != null && m_dev.DbgEngine.IsConnected &&
                //    m_dev.DbgEngine.ConnectionSource == SPOT.Debugger.ConnectionSource.TinyCLR)
                //{
                //    m_dev.DbgEngine.ResumeExecution();
                //}
            }
            catch (ThreadAbortException)
            {
                fAbort = true;
            }
            catch (MFUserExitException)
            {
                fAbort = true;
            }
            catch (Exception e)
            {
                if (!m_evtShutdown.WaitOne(0, false))
                {
                    this.Invoke((MethodInvoker) delegate
                    {
                        MessageBox.Show(this, Properties.Resources.ErrorPrefix + e.Message, Properties.Resources.ApplicationTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    });
                }
            }
            finally
            {
                m_evtDeviceFinished.Set();

                if (m_dev.DbgEngine != null)
                {
                    try
                    {
                        if (m_dev.IsConnected && m_dev.DbgEngine.ConnectionSource == SPOT.Debugger.ConnectionSource.TinyCLR)
                        {
                            m_dev.DbgEngine.ResumeExecution();
                        }
                    }
                    catch
                    {
                    }
                }

                m_dev.OnProgress -= new MFDevice.OnProgressHandler(OnStatus);

                if (!fAbort && !m_evtShutdown.WaitOne(100, false))
                {
                    this.Invoke((MethodInvoker) delegate
                    {
                        Close();
                    });
                }
            }
        }