Index: /trunk/src/VBox/Main/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Main/Makefile.kmk	(revision 57995)
+++ /trunk/src/VBox/Main/Makefile.kmk	(revision 57996)
@@ -359,4 +359,5 @@
 	src-all/SharedFolderImpl.cpp \
 	src-all/AutoCaller.cpp \
+        src-all/ThreadTask.cpp \
 	src-all/VirtualBoxBase.cpp \
 	src-all/VirtualBoxErrorInfoImpl.cpp \
@@ -737,4 +738,5 @@
 	src-all/SharedFolderImpl.cpp \
 	src-all/AutoCaller.cpp \
+        src-all/ThreadTask.cpp \
 	src-all/VirtualBoxBase.cpp \
 	src-all/VirtualBoxErrorInfoImpl.cpp \
@@ -857,4 +859,5 @@
  	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 57995)
+++ /trunk/src/VBox/Main/include/ApplianceImpl.h	(revision 57996)
@@ -114,5 +114,5 @@
 
     struct ImportStack;
-    struct TaskOVF;
+    class 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 57995)
+++ /trunk/src/VBox/Main/include/ApplianceImplPrivate.h	(revision 57996)
@@ -23,4 +23,5 @@
 #include "ovfreader.h"
 #include "SecretKeyStore.h"
+#include "ThreadTask.h"
 #include <map>
 #include <vector>
@@ -122,6 +123,7 @@
 };
 
-struct Appliance::TaskOVF
-{
+class Appliance::TaskOVF: public ThreadTask
+{
+public:
     enum TaskType
     {
@@ -135,5 +137,6 @@
             LocationInfo aLocInfo,
             ComObjPtr<Progress> &aProgress)
-      : pAppliance(aThat),
+      : ThreadTask("TaskOVF"),
+        pAppliance(aThat),
         taskType(aType),
         locInfo(aLocInfo),
@@ -141,9 +144,15 @@
         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;
@@ -155,4 +164,9 @@
 
     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 57995)
+++ /trunk/src/VBox/Main/include/ConsoleImpl.h	(revision 57996)
@@ -563,4 +563,7 @@
     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:
@@ -739,6 +742,4 @@
     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 57995)
+++ /trunk/src/VBox/Main/src-client/ConsoleImpl.cpp	(revision 57996)
@@ -73,4 +73,5 @@
 #include "AutoCaller.h"
 #include "Logging.h"
+#include "ThreadTask.h"
 
 #include <VBox/com/array.h>
@@ -150,11 +151,13 @@
  * Console::addVMCaller() for more info.
  */
-struct VMTask
-{
+class VMTask: public ThreadTask
+{
+public:
     VMTask(Console *aConsole,
            Progress *aProgress,
            const ComPtr<IProgress> &aServerProgress,
            bool aUsesVMPtr)
-        : mConsole(aConsole),
+        : ThreadTask("GenericVMTask"),
+          mConsole(aConsole),
           mConsoleCaller(aConsole),
           mProgress(aProgress),
@@ -175,5 +178,5 @@
     }
 
-    ~VMTask()
+    virtual ~VMTask()
     {
         releaseVMCaller();
@@ -205,6 +208,7 @@
 
 
-struct VMPowerUpTask : public VMTask
-{
+class VMPowerUpTask : public VMTask
+{
+public:
     VMPowerUpTask(Console *aConsole,
                   Progress *aProgress)
@@ -215,5 +219,7 @@
           mTeleporterEnabled(FALSE),
           mEnmFaultToleranceState(FaultToleranceState_Inactive)
-    {}
+    {
+        m_strTaskName = "VMPwrUp";
+    }
 
     PFNCFGMCONSTRUCTOR mConfigConstructor;
@@ -227,13 +233,27 @@
     typedef std::list<ComPtr<IProgress> > ProgressList;
     ProgressList hardDiskProgresses;
+
+    void handler()
+    {
+        int vrc = Console::i_powerUpThread(NULL, this);
+    }
+
 };
 
-struct VMPowerDownTask : public VMTask
-{
+class VMPowerDownTask : public VMTask
+{
+public:
     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);
+    }
 };
 
@@ -2136,29 +2156,18 @@
         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);
-            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))
+            if (!task->isOk())
             {
-                rc = setError(E_FAIL, "Could not create VMPowerDown thread (%Rrc)", vrc);
-                break;
+                throw E_FAIL;
             }
-            /* 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());
+        }
+        catch(...)
+        {
+            delete task;
+            rc = setError(E_FAIL, "Could not create VMPowerDownTask object \n");
             break;
         }
+
+        rc = task->createThread();
 
         /* pass the progress to the caller */
@@ -2169,11 +2178,4 @@
     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;
@@ -6978,5 +6980,4 @@
 HRESULT Console::i_powerUp(IProgress **aProgress, bool aPaused)
 {
-
     LogFlowThisFuncEnter();
 
@@ -6995,4 +6996,5 @@
     LONG cOperations = 1;
     LONG ulTotalOperationsWeight = 1;
+    VMPowerUpTask* task = NULL;
 
     try
@@ -7112,6 +7114,18 @@
         /* Setup task object and thread to carry out the operation
          * asynchronously */
-        std::auto_ptr<VMPowerUpTask> task(new VMPowerUpTask(this, pPowerupProgress));
-        ComAssertComRCRetRC(task->rc());
+        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;
+        }
 
         task->mConfigConstructor = i_configConstructor;
@@ -7371,4 +7385,5 @@
 #endif // 0
 
+        
         /* setup task object and thread to carry out the operation
          * asynchronously */
@@ -7378,12 +7393,8 @@
         }
 
-        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();
+        rc = task->createThread();
+
+        if (FAILED(rc))
+            throw rc;
 
         /* finally, set the state: no right to fail in this method afterwards
@@ -8252,35 +8263,21 @@
                     if (!task->isOk())
                     {
-                        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));
-                        }
+                        LogFlowFunc(("Console is already being uninitialized. \n"));
+                        throw E_FAIL;
                     }
                 }
-                catch(const std::exception &e)
+                catch(...)
                 {
-                    rc = E_FAIL;
-                    LogFlowFunc(("Cought exception! Could not create VMPowerDown thread (%s)\n", e.what()));
+                    delete task;
+                    LogFlowFunc(("Problem with creating VMPowerDownTask object. \n"));
                 }
 
-                if(FAILED(rc) || !task->isOk())
+                rc = task->createThread();
+
+                if (FAILED(rc))
                 {
-                    LogFlowFunc(("Delete task VMPowerDownTask from Console::i_vmstateChangeCallback()\n"));
-                    delete task;
+                    LogFlowFunc(("Problem with creating thread for VMPowerDownTask. \n"));
                 }
+
             }
             break;
@@ -9440,6 +9437,6 @@
     LogFlowFuncEnter();
 
-    std::auto_ptr<VMPowerUpTask> task(static_cast<VMPowerUpTask *>(pvUser));
-    AssertReturn(task.get(), VERR_INVALID_PARAMETER);
+    VMPowerUpTask* task = static_cast<VMPowerUpTask *>(pvUser);
+    AssertReturn(task, VERR_INVALID_PARAMETER);
 
     AssertReturn(!task->mConsole.isNull(), VERR_INVALID_PARAMETER);
@@ -10006,10 +10003,7 @@
     }
 
-    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 57995)
+++ /trunk/src/VBox/Main/src-server/ApplianceImpl.cpp	(revision 57996)
@@ -1185,28 +1185,4 @@
 
 /**
- * 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().
@@ -1220,6 +1196,6 @@
 DECLCALLBACK(int) Appliance::i_taskThreadImportOrExport(RTTHREAD /* aThread */, void *pvUser)
 {
-    std::auto_ptr<TaskOVF> task(static_cast<TaskOVF*>(pvUser));
-    AssertReturn(task.get(), VERR_GENERAL_FAILURE);
+    TaskOVF* task = static_cast<TaskOVF*>(pvUser);
+    AssertReturn(task, VERR_GENERAL_FAILURE);
 
     Appliance *pAppliance = task->pAppliance;
@@ -1234,8 +1210,8 @@
         case TaskOVF::Read:
             if (task->locInfo.storageType == VFSType_File)
-                taskrc = pAppliance->i_readFS(task.get());
+                taskrc = pAppliance->i_readFS(task);
             else if (task->locInfo.storageType == VFSType_S3)
 #ifdef VBOX_WITH_S3
-                taskrc = pAppliance->i_readS3(task.get());
+                taskrc = pAppliance->i_readS3(task);
 #else
                 taskrc = VERR_NOT_IMPLEMENTED;
@@ -1245,8 +1221,8 @@
         case TaskOVF::Import:
             if (task->locInfo.storageType == VFSType_File)
-                taskrc = pAppliance->i_importFS(task.get());
+                taskrc = pAppliance->i_importFS(task);
             else if (task->locInfo.storageType == VFSType_S3)
 #ifdef VBOX_WITH_S3
-                taskrc = pAppliance->i_importS3(task.get());
+                taskrc = pAppliance->i_importS3(task);
 #else
                 taskrc = VERR_NOT_IMPLEMENTED;
@@ -1256,8 +1232,8 @@
         case TaskOVF::Write:
             if (task->locInfo.storageType == VFSType_File)
-                taskrc = pAppliance->i_writeFS(task.get());
+                taskrc = pAppliance->i_writeFS(task);
             else if (task->locInfo.storageType == VFSType_S3)
 #ifdef VBOX_WITH_S3
-                taskrc = pAppliance->i_writeS3(task.get());
+                taskrc = pAppliance->i_writeS3(task);
 #else
                 taskrc = VERR_NOT_IMPLEMENTED;
Index: /trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp	(revision 57995)
+++ /trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp	(revision 57996)
@@ -28,5 +28,4 @@
 #include "ApplianceImpl.h"
 #include "VirtualBoxImpl.h"
-
 #include "ProgressImpl.h"
 #include "MachineImpl.h"
@@ -754,13 +753,22 @@
 
         /* Initialize our worker task */
-        std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Write, aLocInfo, aProgress));
+        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"));
+        }
+
         /* The OVF version to write */
         task->enFormat = aFormat;
 
-        rc = task->startThread();
+        rc = task->createThread();
         if (FAILED(rc)) throw rc;
 
-        /* Don't destruct on success */
-        task.release();
     }
     catch (HRESULT aRC)
@@ -1251,5 +1259,5 @@
     pelmSystem->createChild("vssd:VirtualSystemIdentifier")->addContent(strVMName);
     // <vssd:VirtualSystemType>vmx-4</vssd:VirtualSystemType>
-    const char *pcszHardware = "virtualbox-2.2";
+    const char *pcszHardware = "virtualbox";
     if (enFormat == ovf::OVFVersion_0_9)
         // pretend to be vmware compatible then
Index: /trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp	(revision 57995)
+++ /trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp	(revision 57996)
@@ -874,11 +874,18 @@
 
     /* Initialize our worker task */
-    std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Read, aLocInfo, aProgress));
-
-    rc = task->startThread();
+    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();
     if (FAILED(rc)) throw rc;
-
-    /* Don't destruct on success */
-    task.release();
 
     return rc;
@@ -1371,11 +1378,18 @@
 
     /* Initialize our worker task */
-    std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Import, locInfo, progress));
-
-    rc = task->startThread();
+    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();
     if (FAILED(rc)) throw rc;
-
-    /* Don't destruct on success */
-    task.release();
 
     return rc;
