git-svn-id: https://duplicati.googlecode.com/svn/trunk@1532 59da171f-624f-0410-aa54-27559c288bec
56 lines
1.7 KiB
C#
56 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace Duplicati.GUI.TrayIcon
|
|
{
|
|
/// <summary>
|
|
/// We keep the hosted instance here to allow the TrayIcon executable to load without requiring the Server.exe
|
|
/// </summary>
|
|
internal class HostedInstanceKeeper : IDisposable
|
|
{
|
|
private System.Threading.Thread m_runner;
|
|
private System.Exception m_runnerException = null;
|
|
|
|
public HostedInstanceKeeper(string[] args)
|
|
{
|
|
m_runner = new System.Threading.Thread(ThreadRunner);
|
|
m_runner.Start(args);
|
|
|
|
if (!Duplicati.Server.Program.ServerStartedEvent.WaitOne(TimeSpan.FromSeconds(100), true))
|
|
{
|
|
if (m_runnerException != null)
|
|
throw m_runnerException;
|
|
else
|
|
throw new Exception("Hosted server startup timed out");
|
|
}
|
|
|
|
if (m_runnerException != null)
|
|
throw m_runnerException;
|
|
}
|
|
|
|
private void ThreadRunner(object a)
|
|
{
|
|
try
|
|
{
|
|
Duplicati.Server.Program.Main((string[])a);
|
|
} catch (Exception ex) {
|
|
m_runnerException = ex;
|
|
Duplicati.Server.Program.ServerStartedEvent.Set();
|
|
}
|
|
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Duplicati.Server.Program.ApplicationExitEvent.Set();
|
|
if (!m_runner.Join(TimeSpan.FromSeconds(10)))
|
|
{
|
|
m_runner.Abort();
|
|
m_runner.Join(TimeSpan.FromSeconds(10));
|
|
}
|
|
}
|
|
}
|
|
}
|