Beispiel #1
0
        /// <summary>
        /// Worker thread that actually performs the file generation
        /// </summary>
        void WorkerThread()
        {
            string destFile = m_destinationFile.Text;

            // Set up the necessary delegates we need to invoke methods on the main thread

            WorkerExceptionHandler onException = new WorkerExceptionHandler(WorkerException);
            WorkerFinishedHandler  onFinished  = new WorkerFinishedHandler(WorkerFinished);
            WorkerProgressHandler  onProgress  = new WorkerProgressHandler(WorkerProgress);

            try
            {
                // Attempt to create/replace the main structured storage file.  Notice the
                // completely meaningless pause for dramatic effect

                Invoke(onProgress, new object[] { "Creating the Virtual File System structured storage file" });
                Thread.Sleep(500);

                using (StructuredStorage storage = StructuredStorage.Open(destFile, StorageOpenMode.Create, StorageAccessMode.Exclusive))
                {
                    // If the user did not elect to filter out non-virtualizable ASP.NET stuff,
                    // we can just rip and roar through this without any additional work. Otherwise
                    // use the special case handler for exclusing root items from the VFS

                    if (!m_excludeCommon.Checked)
                    {
                        ProcessStorageFolder(m_sourceFolder.Text, storage, onProgress);
                    }
                    else
                    {
                        ProcessRootStorageFolderSpecial(m_sourceFolder.Text, storage, onProgress);
                    }
                }

                Invoke(onProgress, new object[] { "The Virtual File System was generated successfully" });
                Invoke(onFinished);
            }

            catch (ThreadAbortException)
            {
                // If the thread is aborting, that means the form was closed while the
                // process was still active.  Just nuke the file and exit the thread

                if (File.Exists(destFile))
                {
                    File.Delete(destFile);
                }
            }

            catch (Exception exception)
            {
                if (File.Exists(destFile))
                {
                    File.Delete(destFile);
                }

                // Standard exceptions get pumped back into the main thread to be
                // reported. Also invoke the finish handler since I'm not really
                // spending a lot of time making this a top-notch application :)

                Invoke(onException, new object[] { exception });
                Invoke(onProgress, new object[] { "The Virtual File System could not be generated" });
                Invoke(onFinished);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Worker thread that actually performs the file generation
        /// </summary>
        void WorkerThread()
        {
            string destFile = m_destinationFile.Text;

            // Set up the necessary delegates we need to invoke methods on the main thread

            WorkerExceptionHandler onException = new WorkerExceptionHandler(WorkerException);
            WorkerFinishedHandler onFinished = new WorkerFinishedHandler(WorkerFinished);
            WorkerProgressHandler onProgress = new WorkerProgressHandler(WorkerProgress);

            try
            {
                // Attempt to create/replace the main structured storage file.  Notice the
                // completely meaningless pause for dramatic effect

                Invoke(onProgress, new object[] { "Creating the Virtual File System structured storage file" });
                Thread.Sleep(500);

                using (StructuredStorage storage = StructuredStorage.Open(destFile, StorageOpenMode.Create, StorageAccessMode.Exclusive))
                {
                    // If the user did not elect to filter out non-virtualizable ASP.NET stuff,
                    // we can just rip and roar through this without any additional work. Otherwise
                    // use the special case handler for exclusing root items from the VFS

                    if (!m_excludeCommon.Checked) ProcessStorageFolder(m_sourceFolder.Text, storage, onProgress);
                    else ProcessRootStorageFolderSpecial(m_sourceFolder.Text, storage, onProgress);
                }

                Invoke(onProgress, new object[] { "The Virtual File System was generated successfully" });
                Invoke(onFinished);
            }

            catch (ThreadAbortException)
            {
                // If the thread is aborting, that means the form was closed while the
                // process was still active.  Just nuke the file and exit the thread

                if (File.Exists(destFile)) File.Delete(destFile);
            }

            catch (Exception exception)
            {
                if (File.Exists(destFile)) File.Delete(destFile);

                // Standard exceptions get pumped back into the main thread to be
                // reported. Also invoke the finish handler since I'm not really
                // spending a lot of time making this a top-notch application :)

                Invoke(onException, new object[] { exception });
                Invoke(onProgress, new object[] { "The Virtual File System could not be generated" });
                Invoke(onFinished);
            }
        }