Index: src/ch/MainWnd.cpp
===================================================================
diff -u -N -rbeaf6c76a528f2bcf42efa705770079fd84c0156 -r25129f39720523eca2cb702242890a7862f70ec6
--- src/ch/MainWnd.cpp	(.../MainWnd.cpp)	(revision beaf6c76a528f2bcf42efa705770079fd84c0156)
+++ src/ch/MainWnd.cpp	(.../MainWnd.cpp)	(revision 25129f39720523eca2cb702242890a7862f70ec6)
@@ -45,6 +45,7 @@
 #include "DirectoryChooser.h"
 #include "FeedbackHandlerFactory.h"
 #include "../libchcore/TTask.h"
+#include "TTaskManagerWrapper.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -197,7 +198,7 @@
 
 		// start clipboard monitoring
 		LOG_INFO(_T("Starting clipboard monitor..."));
-		CClipboardMonitor::StartMonitor(m_spTasks.get());
+		CClipboardMonitor::StartMonitor(m_spTasks);
 
 		CheckForUpdates();
 
@@ -381,7 +382,35 @@
 
 void CMainWnd::OnClose() 
 {
-	PrepareToExit();
+	CString strMessage;
+	try
+	{
+		PrepareToExit();
+	}
+	catch(const chcore::TBaseException& e)
+	{
+		const size_t stMaxError = 1024;
+		wchar_t szError[ stMaxError ];
+		e.GetErrorInfo(szError, stMaxError);
+
+		strMessage = szError;
+	}
+	catch(const std::exception& e)
+	{
+		strMessage = e.what();
+	}
+
+	if(!strMessage.IsEmpty())
+	{
+		LOG_ERROR(L"Failed to finalize tasks before exiting Copy Handler. Error: " + strMessage);
+
+		ictranslate::CFormat fmt;
+
+		fmt.SetFormat(GetResManager().LoadString(IDS_FINALIZE_CH_ERROR));
+		fmt.SetParam(_T("%reason"), strMessage);
+		AfxMessageBox(fmt, MB_OK | MB_ICONERROR);
+	}
+
 	CWnd::OnClose();
 }
 
@@ -390,12 +419,27 @@
 	switch (nIDEvent)
 	{
 	case 1023:
-		// autosave timer
-		KillTimer(1023);
-		m_spTasks->Store(false);
-		SetTimer(1023, GetPropValue<PP_PAUTOSAVEINTERVAL>(GetConfig()), NULL);
-		break;
+		{
+			// autosave timer
+			KillTimer(1023);
+			try
+			{
+				m_spTasks->Store(false);
+			}
+			catch(const std::exception& e)
+			{
+				CString strError = e.what();
 
+				ictranslate::CFormat fmt;
+				fmt.SetFormat(_T("Failed to autosave task. Error: %err."));
+				fmt.SetParam(_T("%err"), (PCTSTR)strError);
+
+				LOG_ERROR(fmt);
+			}
+
+			SetTimer(1023, GetPropValue<PP_PAUTOSAVEINTERVAL>(GetConfig()), NULL);
+			break;
+		}
 	case 3245:
 		// auto-delete finished tasks timer
 		KillTimer(3245);
@@ -512,16 +556,9 @@
 					break;
 			}
 
-			// load resource strings
-			chcore::SetTaskPropValue<chcore::eTO_AlternateFilenameFormatString_First>(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_FIRSTCOPY_STRING));
-			chcore::SetTaskPropValue<chcore::eTO_AlternateFilenameFormatString_AfterFirst>(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_NEXTCOPY_STRING));
+			TTaskManagerWrapper tTaskManager(m_spTasks);
+			tTaskManager.CreateTask(tTaskDefinition);
 
-			// create task with the above definition
-			chcore::TTaskPtr spTask = m_spTasks->CreateTask(tTaskDefinition);
-
-			// add to task list and start processing
-			spTask->BeginProcessing();
-
 			break;
 		}
 	case eCDType_CommandLineArguments:
@@ -622,15 +659,8 @@
 
 		chcore::TTaskDefinition tTaskDefinition = dlg.m_tTaskDefinition;
 
-		// load resource strings
-		chcore::SetTaskPropValue<chcore::eTO_AlternateFilenameFormatString_First>(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_FIRSTCOPY_STRING));
-		chcore::SetTaskPropValue<chcore::eTO_AlternateFilenameFormatString_AfterFirst>(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_NEXTCOPY_STRING));
-
-		// new task
-		chcore::TTaskPtr spTask = m_spTasks->CreateTask(tTaskDefinition);
-
-		// start
-		spTask->BeginProcessing();
+		TTaskManagerWrapper tTaskManager(m_spTasks);
+		tTaskManager.CreateTask(tTaskDefinition);
 	}
 }