public object Clone()
 {
     var msg = new InternalMessage(MessageType, Content)
         {
             SourceThread = SourceThread,
             TimeStamp = TimeStamp,
             Id = Id
         };
     return msg;
 }
 private void HandleTerminate(InternalMessage internalMessage)
 {
     if (_terminating) return;
     _terminating = true;
     var force = (bool)internalMessage.Content;
     var thrs = new List<ThreadDescriptor>();
     foreach (var thread in _runningThreads.Values)
     {
         thrs.Add(thread);
     }
     _runningThreads = new Dictionary<string, ThreadDescriptor>();
     foreach (var thread in thrs)
     {
         if (thread != null)
         {
             thread.Thread.Terminate(force);
         }
     }
     _terminating = false;
     base.Terminate(force);
 }
 private void HandleRunThread(InternalMessage internalMessage)
 {
     var threadName = internalMessage.Content as string;
     if (threadName != null)
     {
         if (_runningThreads.ContainsKey(threadName))
         {
             var thread = _runningThreads[threadName];
             thread.Thread.RunThread();
         }
     }
 }
        private void HandleRemoveThread(InternalMessage internalMessage)
        {
            if (_terminating) return;

            var th = internalMessage.Content as RemoveThreadContent;
            if (th != null)
            {
                if (_runningThreads.ContainsKey(th.ThreadName))
                {
                    var thread = _runningThreads[th.ThreadName];
                    _runningThreads[th.ThreadName] = null;
                    /*ThreadDescriptor outThread;
                    _runningThreads.TryRemove(th.ThreadName, out outThread);*/
                    thread.Thread.Terminate(th.ForceHalt);
                    _runningThreads.Remove(th.ThreadName);
                }
            }
        }
 private void HandleRegisterMessageType(InternalMessage internalMessage)
 {
     internalMessage.SourceThread = internalMessage.SourceThread.ToUpper();
     if (_runningThreads.ContainsKey(internalMessage.SourceThread))
     {
         ThreadDescriptor td;
         if (internalMessage.Content as Type != null && _runningThreads.TryGetValue(internalMessage.SourceThread, out td))
         {
             if (!td.RegisteredTypes.ContainsKey((Type)internalMessage.Content))
             {
                 td.RegisteredTypes.Add((Type)internalMessage.Content, true);
             }
         }
     }
 }
 private void HandleAddThread(InternalMessage internalMessage)
 {
     var th = internalMessage.Content as IBaseMessageThread;
     if (th != null)
     {
         if (!_runningThreads.ContainsKey(th.ThreadName))
         {
             th.Manager = this;
             _runningThreads[th.ThreadName] = new ThreadDescriptor(th);
             th.RunThread();
             th.RegisterMessages();
         }
     }
 }