コード例 #1
0
ファイル: Program.cs プロジェクト: S031/IpcChannel
        private static IpcPipeServer StartServerWithThreadClient(CancellationToken cancellationToken)
        {
            IpcPipeServer s = new IpcPipeServer(new IpcPipeServerOptions()
            {
                CancellationToken = cancellationToken
            });

            Task.Run(async() => await StartClient(s.PipeReadHandle, s.PipeWriteHandle), cancellationToken);
            return(s);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: S031/IpcChannel
        static async Task Main(string[] args)
        {
            using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource())
            {
                CancellationToken cancellationToken = cancellationTokenSource.Token;
#if DEBUG
                Logger.LoggerOptions.LoggingLevel = LogLevel.Debug;
#else
                Logger.LoggerOptions.LoggingLevel = LogLevel.Information;
#endif

                if (args.Length == 0)
                {
                    //Log for this will be one
                    Logger.LoggerOptions.LogName = "IpcPipeServer-";
                    Logger.LogInfo("Started application (Process A)...", true);
                    using (IpcPipeServer s = start_client_in_thread
                                                ? StartServerWithThreadClient(cancellationToken)
                                                : StartServerWithProcessClient(cancellationToken))
                    {
                        Logger.LogInfo($"Start loop for {loop_count} iterations", true);
                        DateTime d = DateTime.Now;
                        for (int i = 0; i < loop_count; i++)
                        {
                            var r = await s.CallMethod($"TestMethod{i}").ConfigureAwait(false);
                        }
                        Logger.LogInfo($"End loop for {loop_count} iterations with {(DateTime.Now - d).TotalMilliseconds} ms", true);
                        await s.CloseChannel().ConfigureAwait(false);

                        Console.ReadLine();
                    }
                }
                else
                {
                    //Client runing in process mode
                    Logger.LoggerOptions.LogName = "IpcPipeClient-";
                    await StartClient(args[0], args[1], cancellationToken);
                }
                Logger.Flush();
            }
        }