public void StartProfiling(int profiledProcessId, Guid agentApplicationUid)
        {
            //Profiling is already started or decoding in progress
            if (_profiledProcess != null)
            {
                return;
            }
            DirectoryInfo profilingResultsDirectory = _application.ApplicationSettings.ProfilingResults.GetDirectory();
            string        profilingResultsFile      = Path.Combine(profilingResultsDirectory.FullName, _application.Uid.ToString("N"));

            _storage                 = new DataStorage(profilingResultsFile);
            _profiledProcess         = new ProfiledProcessManager(profiledProcessId);
            _profiledProcess.Exited += OnProfiledProcessExited;
            ProcessInformation       = _profiledProcess.GetProcessInformation();
            IStreamFactory streamFactory = Connector.Native.StreamFactory;

            _requestServer = new RequestServer();
            _requestServer.Run(streamFactory.CreateInvokeStream());
            _gatewayServer = new NativeGatewayServer(_agentLibrary, Connector.ApplicationUid, _application.ConfigurationSettings.GatewaySettings); //new ManagedGatewayServer(streamFactory, _application.Settings.GatewaySettings);//
            _agentClient   = new RequestClient(streamFactory.OpenInvokeStream(agentApplicationUid));
            ConfigurationSettings           configurationSettings  = _application.ConfigurationSettings;
            ProfilingTypeSettingsCollection profilingTypesSettings = configurationSettings.ProfilingTypesSettings;

            _profilingTypesManager = new ProfilingTypeManager(_profilingTypes, profilingTypesSettings);
            _profilingTypesManager.AttachStorage(_storage);
            _profilingTypesManager.ExportServices(_application.ServiceContainer);
            _profilingTypesManager.ImportServices(_application.ServiceContainer);
            _profilingTypesManager.StartProfiling(_gatewayServer);
            _gatewayServer.Lock();
            _gatewayServer.Start();
            _application.RaiseSessionStateChanged();
        }