Index: /trunk/src/VBox/Main/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Main/Makefile.kmk	(revision 58001)
+++ /trunk/src/VBox/Main/Makefile.kmk	(revision 58002)
@@ -359,5 +359,4 @@
 	src-all/SharedFolderImpl.cpp \
 	src-all/AutoCaller.cpp \
-        src-all/ThreadTask.cpp \
 	src-all/VirtualBoxBase.cpp \
 	src-all/VirtualBoxErrorInfoImpl.cpp \
@@ -738,5 +737,4 @@
 	src-all/SharedFolderImpl.cpp \
 	src-all/AutoCaller.cpp \
-        src-all/ThreadTask.cpp \
 	src-all/VirtualBoxBase.cpp \
 	src-all/VirtualBoxErrorInfoImpl.cpp \
@@ -859,5 +857,4 @@
  	src-all/Global.cpp \
 	src-all/AutoCaller.cpp \
-        src-all/ThreadTask.cpp \
  	src-all/VirtualBoxBase.cpp \
  	src-all/VirtualBoxErrorInfoImpl.cpp \
Index: /trunk/src/VBox/Main/include/ApplianceImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/ApplianceImpl.h	(revision 58001)
+++ /trunk/src/VBox/Main/include/ApplianceImpl.h	(revision 58002)
@@ -114,5 +114,5 @@
 
     struct ImportStack;
-    class TaskOVF;
+    struct TaskOVF;
     struct Data;            // opaque, defined in ApplianceImpl.cpp
     Data *m;
Index: /trunk/src/VBox/Main/include/ApplianceImplPrivate.h
===================================================================
--- /trunk/src/VBox/Main/include/ApplianceImplPrivate.h	(revision 58001)
+++ /trunk/src/VBox/Main/include/ApplianceImplPrivate.h	(revision 58002)
@@ -23,5 +23,4 @@
 #include "ovfreader.h"
 #include "SecretKeyStore.h"
-#include "ThreadTask.h"
 #include <map>
 #include <vector>
@@ -123,7 +122,6 @@
 };
 
-class Appliance::TaskOVF: public ThreadTask
-{
-public:
+struct Appliance::TaskOVF
+{
     enum TaskType
     {
@@ -137,6 +135,5 @@
             LocationInfo aLocInfo,
             ComObjPtr<Progress> &aProgress)
-      : ThreadTask("TaskOVF"),
-        pAppliance(aThat),
+      : pAppliance(aThat),
         taskType(aType),
         locInfo(aLocInfo),
@@ -144,15 +141,9 @@
         enFormat(ovf::OVFVersion_unknown),
         rc(S_OK)
-    {
-        switch (taskType)
-        {
-            case TaskOVF::Read:     m_strTaskName = "ApplRead"; break;
-            case TaskOVF::Import:   m_strTaskName = "ApplImp"; break;
-            case TaskOVF::Write:    m_strTaskName = "ApplWrit"; break;
-            default:                m_strTaskName = "ApplTask"; break;
-        }
-    }
+    {}
 
     static DECLCALLBACK(int) updateProgress(unsigned uPercent, void *pvUser);
+
+    HRESULT startThread();
 
     Appliance *pAppliance;
@@ -164,9 +155,4 @@
 
     HRESULT rc;
-
-    void handler()
-    {
-        int vrc = Appliance::i_taskThreadImportOrExport(NULL, this);
-    }
 };
 
Index: /trunk/src/VBox/Main/include/ConsoleImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/ConsoleImpl.h	(revision 58001)
+++ /trunk/src/VBox/Main/include/ConsoleImpl.h	(revision 58002)
@@ -563,7 +563,4 @@
     typedef std::map<Utf8Str, ComPtr<IMediumAttachment> > MediumAttachmentMap;
     typedef std::list <USBStorageDevice> USBStorageDeviceList;
-
-    static DECLCALLBACK(int)    i_powerUpThread(RTTHREAD Thread, void *pvUser);
-    static DECLCALLBACK(int)    i_powerDownThread(RTTHREAD Thread, void *pvUser);
 
 private:
@@ -742,4 +739,6 @@
     void                        i_detachAllUSBDevices(bool aDone);
 
+    static DECLCALLBACK(int)    i_powerUpThread(RTTHREAD Thread, void *pvUser);
+    static DECLCALLBACK(int)    i_powerDownThread(RTTHREAD Thread, void *pvUser);
 
     static DECLCALLBACK(int)    i_vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM);
Index: /trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/ConsoleImpl.cpp	(revision 58001)
+++ /trunk/src/VBox/Main/src-client/ConsoleImpl.cpp	(revision 58002)
@@ -73,5 +73,4 @@
 #include "AutoCaller.h"
 #include "Logging.h"
-#include "ThreadTask.h"
 
 #include <VBox/com/array.h>
@@ -151,13 +150,11 @@
  * Console::addVMCaller() for more info.
  */
-class VMTask: public ThreadTask
-{
-public:
+struct VMTask
+{
     VMTask(Console *aConsole,
            Progress *aProgress,
            const ComPtr<IProgress> &aServerProgress,
            bool aUsesVMPtr)
-        : ThreadTask("GenericVMTask"),
-          mConsole(aConsole),
+        : mConsole(aConsole),
           mConsoleCaller(aConsole),
           mProgress(aProgress),
@@ -178,5 +175,5 @@
     }
 
-    virtual ~VMTask()
+    ~VMTask()
     {
         releaseVMCaller();
@@ -208,7 +205,6 @@
 
 
-class VMPowerUpTask : public VMTask
-{
-public:
+struct VMPowerUpTask : public VMTask
+{
     VMPowerUpTask(Console *aConsole,
                   Progress *aProgress)
@@ -219,7 +215,5 @@
           mTeleporterEnabled(FALSE),
           mEnmFaultToleranceState(FaultToleranceState_Inactive)
-    {
-        m_strTaskName = "VMPwrUp";
-    }
+    {}
 
     PFNCFGMCONSTRUCTOR mConfigConstructor;
@@ -233,27 +227,13 @@
     typedef std::list<ComPtr<IProgress> > ProgressList;
     ProgressList hardDiskProgresses;
-
-    void handler()
-    {
-        int vrc = Console::i_powerUpThread(NULL, this);
-    }
-
 };
 
-class VMPowerDownTask : public VMTask
-{
-public:
+struct VMPowerDownTask : public VMTask
+{
     VMPowerDownTask(Console *aConsole,
                     const ComPtr<IProgress> &aServerProgress)
         : VMTask(aConsole, NULL /* aProgress */, aServerProgress,
                  true /* aUsesVMPtr */)
-    {
-        m_strTaskName = "VMPwrDwn";
-    }
-
-    void handler()
-    {
-        int vrc = Console::i_powerDownThread(NULL, this);
-    }
+    {}
 };
 
@@ -2156,18 +2136,29 @@
         try
         {
+            /* Setup task object and thread to carry out the operation asynchronously.
+             * We are going to pass ownership of task pointer to another thread.
+             * So we are in charge of deletion this task pointer in case if RTThreadCreate 
+             * returns not successful result or in case of any exception 
+             */
+            
             task = new VMPowerDownTask(this, pProgress);
-            if (!task->isOk())
+            AssertBreakStmt(task->isOk(), rc = E_FAIL);
+            int vrc = RTThreadCreate(NULL, Console::i_powerDownThread,
+                                     (void *) task, 0,
+                                     RTTHREADTYPE_MAIN_WORKER, 0,
+                                     "VMPwrDwn");
+            if (RT_FAILURE(vrc))
             {
-                throw E_FAIL;
+                rc = setError(E_FAIL, "Could not create VMPowerDown thread (%Rrc)", vrc);
+                break;
             }
-        }
-        catch(...)
-        {
-            delete task;
-            rc = setError(E_FAIL, "Could not create VMPowerDownTask object \n");
+            /* task is now owned by powerDownThread(), so release it */
+            //task.release();
+        }
+        catch(const std::exception &e)
+        {
+            rc = setError(E_FAIL, "Cought exception! Could not create VMPowerDown thread (%s)", e.what());
             break;
         }
-
-        rc = task->createThread();
 
         /* pass the progress to the caller */
@@ -2178,4 +2169,11 @@
     if (FAILED(rc))
     {
+        if (task != NULL)
+        {
+            //we can delete this pointer because something
+            //was wrong and we hadn't passed pointer to another thread
+            LogFlowFunc(("Delete task VMPowerDownTask from Console::powerDown()\n"));
+            delete task;
+        }
         /* preserve existing error info */
         ErrorInfoKeeper eik;
@@ -6980,4 +6978,5 @@
 HRESULT Console::i_powerUp(IProgress **aProgress, bool aPaused)
 {
+
     LogFlowThisFuncEnter();
 
@@ -6996,5 +6995,4 @@
     LONG cOperations = 1;
     LONG ulTotalOperationsWeight = 1;
-    VMPowerUpTask* task = NULL;
 
     try
@@ -7112,20 +7110,9 @@
         }
 
+
         /* Setup task object and thread to carry out the operation
          * asynchronously */
-        try
-        {
-            task = new VMPowerUpTask(this, pPowerupProgress);
-            if (!task->isOk())
-            {
-                throw E_FAIL;
-            }
-        }
-        catch(...)
-        {
-            delete task;
-            rc = setError(E_FAIL, "Could not create VMPowerUpTask object \n");
-            throw rc;
-        }
+        std::auto_ptr<VMPowerUpTask> task(new VMPowerUpTask(this, pPowerupProgress));
+        ComAssertComRCRetRC(task->rc());
 
         task->mConfigConstructor = i_configConstructor;
@@ -7385,5 +7372,4 @@
 #endif // 0
 
-        
         /* setup task object and thread to carry out the operation
          * asynchronously */
@@ -7393,8 +7379,12 @@
         }
 
-        rc = task->createThread();
-
-        if (FAILED(rc))
-            throw rc;
+        int vrc = RTThreadCreate(NULL, Console::i_powerUpThread,
+                                 (void *)task.get(), 0,
+                                 RTTHREADTYPE_MAIN_WORKER, 0, "VMPwrUp");
+        if (RT_FAILURE(vrc))
+            throw setError(E_FAIL, "Could not create VMPowerUp thread (%Rrc)", vrc);
+
+        /* task is now owned by powerUpThread(), so release it */
+        task.release();
 
         /* finally, set the state: no right to fail in this method afterwards
@@ -8263,21 +8253,35 @@
                     if (!task->isOk())
                     {
-                        LogFlowFunc(("Console is already being uninitialized. \n"));
-                        throw E_FAIL;
+                        LogFlowFunc(("Console is already being uninitialized.\n"));
+                    }
+                    else
+                    {
+                        /*
+                         * We are going to pass ownership of task pointer to another thread.
+                         * So we are in charge of deletion this task pointer in case if RTThreadCreate
+                         * returns not successful result or in case of any exception
+                         */
+                        int vrc = RTThreadCreate(NULL, Console::i_powerDownThread,
+                                                 (void *) task, 0,
+                                                 RTTHREADTYPE_MAIN_WORKER, 0,
+                                                 "VMPwrDwn");
+                        if (RT_FAILURE(vrc))
+                        {
+                            rc = E_FAIL;
+                            LogFlowFunc(("Could not create VMPowerDown thread (%Rrc)\n", vrc));
+                        }
                     }
                 }
-                catch(...)
+                catch(const std::exception &e)
                 {
+                    rc = E_FAIL;
+                    LogFlowFunc(("Cought exception! Could not create VMPowerDown thread (%s)\n", e.what()));
+                }
+
+                if(FAILED(rc) || !task->isOk())
+                {
+                    LogFlowFunc(("Delete task VMPowerDownTask from Console::i_vmstateChangeCallback()\n"));
                     delete task;
-                    LogFlowFunc(("Problem with creating VMPowerDownTask object. \n"));
                 }
-
-                rc = task->createThread();
-
-                if (FAILED(rc))
-                {
-                    LogFlowFunc(("Problem with creating thread for VMPowerDownTask. \n"));
-                }
-
             }
             break;
@@ -9437,6 +9441,6 @@
     LogFlowFuncEnter();
 
-    VMPowerUpTask* task = static_cast<VMPowerUpTask *>(pvUser);
-    AssertReturn(task, VERR_INVALID_PARAMETER);
+    std::auto_ptr<VMPowerUpTask> task(static_cast<VMPowerUpTask *>(pvUser));
+    AssertReturn(task.get(), VERR_INVALID_PARAMETER);
 
     AssertReturn(!task->mConsole.isNull(), VERR_INVALID_PARAMETER);
@@ -10003,7 +10007,10 @@
     }
 
+    LogFlowFunc(("Delete task VMPowerDownTask from Console::i_powerDownThread()\n"));
+    delete task;
     LogFlowFuncLeave();
     return rc;
 }
+
 
 /**
Index: /trunk/src/VBox/Main/src-server/ApplianceImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/ApplianceImpl.cpp	(revision 58001)
+++ /trunk/src/VBox/Main/src-server/ApplianceImpl.cpp	(revision 58002)
@@ -1185,4 +1185,28 @@
 
 /**
+ * Starts the worker thread for the task.
+ *
+ * @return COM status code.
+ */
+HRESULT Appliance::TaskOVF::startThread()
+{
+    /* Pick a thread name suitable for logging (<= 8 chars). */
+    const char *pszTaskNm;
+    switch (taskType)
+    {
+        case TaskOVF::Read:     pszTaskNm = "ApplRead"; break;
+        case TaskOVF::Import:   pszTaskNm = "ApplImp"; break;
+        case TaskOVF::Write:    pszTaskNm = "ApplWrit"; break;
+        default:                pszTaskNm = "ApplTask"; break;
+    }
+
+    int vrc = RTThreadCreate(NULL, Appliance::i_taskThreadImportOrExport, this,
+                             0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0, pszTaskNm);
+    if (RT_SUCCESS(vrc))
+        return S_OK;
+    return Appliance::i_setErrorStatic(E_FAIL, Utf8StrFmt("Could not create OVF task thread (%Rrc)\n", vrc));
+}
+
+/**
  * Thread function for the thread started in Appliance::readImpl() and Appliance::importImpl()
  * and Appliance::writeImpl().
@@ -1196,6 +1220,6 @@
 DECLCALLBACK(int) Appliance::i_taskThreadImportOrExport(RTTHREAD /* aThread */, void *pvUser)
 {
-    TaskOVF* task = static_cast<TaskOVF*>(pvUser);
-    AssertReturn(task, VERR_GENERAL_FAILURE);
+    std::auto_ptr<TaskOVF> task(static_cast<TaskOVF*>(pvUser));
+    AssertReturn(task.get(), VERR_GENERAL_FAILURE);
 
     Appliance *pAppliance = task->pAppliance;
@@ -1210,8 +1234,8 @@
         case TaskOVF::Read:
             if (task->locInfo.storageType == VFSType_File)
-                taskrc = pAppliance->i_readFS(task);
+                taskrc = pAppliance->i_readFS(task.get());
             else if (task->locInfo.storageType == VFSType_S3)
 #ifdef VBOX_WITH_S3
-                taskrc = pAppliance->i_readS3(task);
+                taskrc = pAppliance->i_readS3(task.get());
 #else
                 taskrc = VERR_NOT_IMPLEMENTED;
@@ -1221,8 +1245,8 @@
         case TaskOVF::Import:
             if (task->locInfo.storageType == VFSType_File)
-                taskrc = pAppliance->i_importFS(task);
+                taskrc = pAppliance->i_importFS(task.get());
             else if (task->locInfo.storageType == VFSType_S3)
 #ifdef VBOX_WITH_S3
-                taskrc = pAppliance->i_importS3(task);
+                taskrc = pAppliance->i_importS3(task.get());
 #else
                 taskrc = VERR_NOT_IMPLEMENTED;
@@ -1232,8 +1256,8 @@
         case TaskOVF::Write:
             if (task->locInfo.storageType == VFSType_File)
-                taskrc = pAppliance->i_writeFS(task);
+                taskrc = pAppliance->i_writeFS(task.get());
             else if (task->locInfo.storageType == VFSType_S3)
 #ifdef VBOX_WITH_S3
-                taskrc = pAppliance->i_writeS3(task);
+                taskrc = pAppliance->i_writeS3(task.get());
 #else
                 taskrc = VERR_NOT_IMPLEMENTED;
Index: /trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp	(revision 58001)
+++ /trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp	(revision 58002)
@@ -28,4 +28,5 @@
 #include "ApplianceImpl.h"
 #include "VirtualBoxImpl.h"
+
 #include "ProgressImpl.h"
 #include "MachineImpl.h"
@@ -753,22 +754,13 @@
 
         /* Initialize our worker task */
-        TaskOVF* task = NULL;
-        try
-        {
-            task = new TaskOVF(this, TaskOVF::Write, aLocInfo, aProgress);
-        }
-        catch(...)
-        {
-            delete task;
-            throw rc = setError(VBOX_E_OBJECT_NOT_FOUND, 
-                                tr("Could not create TaskOVF object for for writing out the OVF to disk"));
-        }
-
+        std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Write, aLocInfo, aProgress));
         /* The OVF version to write */
         task->enFormat = aFormat;
 
-        rc = task->createThread();
+        rc = task->startThread();
         if (FAILED(rc)) throw rc;
 
+        /* Don't destruct on success */
+        task.release();
     }
     catch (HRESULT aRC)
Index: /trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp	(revision 58001)
+++ /trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp	(revision 58002)
@@ -874,18 +874,11 @@
 
     /* Initialize our worker task */
-    TaskOVF* task = NULL;
-    try
-    {
-        task = new TaskOVF(this, TaskOVF::Read, aLocInfo, aProgress);
-    }
-    catch(...)
-    {
-        delete task;
-        throw rc = setError(VBOX_E_OBJECT_NOT_FOUND, 
-                            tr("Could not create TaskOVF object for reading the OVF from disk"));
-    }
-
-    rc = task->createThread();
+    std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Read, aLocInfo, aProgress));
+
+    rc = task->startThread();
     if (FAILED(rc)) throw rc;
+
+    /* Don't destruct on success */
+    task.release();
 
     return rc;
@@ -1378,18 +1371,11 @@
 
     /* Initialize our worker task */
-    TaskOVF* task = NULL;
-    try
-    {
-        task = new TaskOVF(this, TaskOVF::Import, locInfo, progress);
-    }
-    catch(...)
-    {
-        delete task;
-        throw rc = setError(VBOX_E_OBJECT_NOT_FOUND, 
-                            tr("Could not create TaskOVF object for importing OVF data into VirtualBox"));
-    }
-
-    rc = task->createThread();
+    std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Import, locInfo, progress));
+
+    rc = task->startThread();
     if (FAILED(rc)) throw rc;
+
+    /* Don't destruct on success */
+    task.release();
 
     return rc;
