private void InvokeWkHtmlToPdf(WKHtmlToPDFParameters parameters, WkHtmlToPdfParametersInternal parametersInternal)
        {
            if (_processHelper._process != null)
            {
                throw new InvalidOperationException("WkHtmlToPdf process is already started");
            }

            if (UseStandaloneWkHtmlToPdfTool == false)
            {
                ExtractWkHtmlToPdfFiles();
            }

            string lastErrorLine = string.Empty;

            WKHtmlToPDFParameterBuilder wkHtmlToPDFParameterBuilder = new WKHtmlToPDFParameterBuilder(parameters, parametersInternal);
            var args = wkHtmlToPDFParameterBuilder.BuildString();

            try
            {
                _processHelper._process = Process.Start(new ProcessStartInfo(this.GetToolExePath(), args)
                {
                    WindowStyle            = ProcessWindowStyle.Hidden,
                    CreateNoWindow         = true,
                    UseShellExecute        = false,
                    WorkingDirectory       = Path.GetDirectoryName(this.PdfToolDirectory),
                    RedirectStandardInput  = false,
                    RedirectStandardOutput = false,
                    RedirectStandardError  = true
                });

                _processHelper._process.ErrorDataReceived += _wkHtmlToPdfProcess_ErrorDataReceived;
                _processHelper._process.BeginErrorReadLine();
                _processHelper.WaitWkHtmlProcessForExit();

                long num            = 0;
                var  outputFileName = parametersInternal.OutputFileParameter.Value;
                if (File.Exists(outputFileName))
                {
                    num = new FileInfo(outputFileName).Length;
                }
                this.CheckExitCode(_processHelper._process.ExitCode, lastErrorLine, num > 0L);
            }
            finally
            {
                _processHelper.EnsureWkHtmlProcessStopped();
            }

            void _wkHtmlToPdfProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
            {
                if (e.Data == null)
                {
                    return;
                }
                if (!string.IsNullOrEmpty(e.Data))
                {
                    lastErrorLine = e.Data;
                }
                if (this.LogReceived == null)
                {
                    return;
                }

                this.LogReceived((object)this, e);
            }
        }
        private void InvokeWkHtmlToPdfInInBatch(WKHtmlToPDFParameters parameters, WkHtmlToPdfParametersInternal parametersInternal)
        {
            string lastErrorLine = string.Empty;

            WKHtmlToPDFParameterBuilder wkHtmlToPDFParameterBuilder = new WKHtmlToPDFParameterBuilder(parameters, parametersInternal);
            var args = wkHtmlToPDFParameterBuilder.BuildString();

            if (_processHelper._process == null || _processHelper._process.HasExited)
            {
                _processHelper._process = Process.Start(new ProcessStartInfo(GetToolExePath(), "--read-args-from-stdin")
                {
                    WindowStyle            = ProcessWindowStyle.Hidden,
                    CreateNoWindow         = true,
                    UseShellExecute        = false,
                    WorkingDirectory       = Path.GetDirectoryName(this.PdfToolDirectory),
                    RedirectStandardInput  = true,
                    RedirectStandardOutput = false,
                    RedirectStandardError  = true
                });

                _processHelper._process.BeginErrorReadLine();
            }

            _processHelper._process.ErrorDataReceived += _wkHtmlToPdfProcess_ErrorDataReceived;

            try
            {
                var outputFile = parametersInternal.OutputFileParameter.Value;

                if (File.Exists(outputFile))
                {
                    File.Delete(outputFile);
                }

                _processHelper._process.StandardInput.WriteLine(args.Replace('\\', '/'));
                bool flag = true;
                while (flag)
                {
                    Thread.Sleep(25);
                    if (_processHelper._process.HasExited)
                    {
                        flag = false;
                    }
                    if (File.Exists(outputFile))
                    {
                        flag = false;
                        this.WaitForFile(outputFile);
                    }
                }

                if (!_processHelper._process.HasExited)
                {
                    return;
                }

                this.CheckExitCode(_processHelper._process.ExitCode, lastErrorLine, File.Exists(outputFile));
            }
            finally
            {
                if (_processHelper._process != null && !_processHelper._process.HasExited)
                {
                    _processHelper._process.ErrorDataReceived -= _wkHtmlToPdfProcess_ErrorDataReceived;
                }
                else
                {
                    _processHelper.EnsureWkHtmlProcessStopped();
                }
            }

            void _wkHtmlToPdfProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e) // o, args
            {
                if (e.Data == null)
                {
                    return;
                }
                if (!string.IsNullOrEmpty(e.Data))
                {
                    lastErrorLine = e.Data;
                }
                if (this.LogReceived == null)
                {
                    return;
                }

                this.LogReceived((object)this, e);
            }
        }