{"id":16494685,"url":"https://github.com/rambalac/processthreads","last_synced_at":"2025-10-27T21:31:20.639Z","repository":{"id":144187503,"uuid":"44793747","full_name":"Rambalac/ProcessThreads","owner":"Rambalac","description":"Runs static methods in separate process","archived":false,"fork":false,"pushed_at":"2015-11-16T05:50:08.000Z","size":0,"stargazers_count":4,"open_issues_count":2,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-01T08:41:40.793Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Rambalac.png","metadata":{"files":{"readme":"ReadMe.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-23T05:59:07.000Z","updated_at":"2023-09-02T21:35:46.000Z","dependencies_parsed_at":"2023-03-21T16:43:28.135Z","dependency_job_id":null,"html_url":"https://github.com/Rambalac/ProcessThreads","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rambalac%2FProcessThreads","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rambalac%2FProcessThreads/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rambalac%2FProcessThreads/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rambalac%2FProcessThreads/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rambalac","download_url":"https://codeload.github.com/Rambalac/ProcessThreads/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238560937,"owners_count":19492612,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T14:15:01.706Z","updated_at":"2025-10-27T21:31:15.330Z","avatar_url":"https://github.com/Rambalac.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"Process threads\n===============\nRuns methods in separate process.\n\nAll parameters and method targets must be Serializable.\nExpression in ```Start``` method must be method call expressions. You still can use something like \n```\nmanager.Start(()=\u003e(\"asd\"+\"fgh\").MyExtensionMethod(var1+var2))\n``` \nBut you cannot use \n```\nmanager.Start(()=\u003eMyMethod1(var)+MyMethod2()))\n```\nAll method targets and parameters are computed on caller process before executing method on separate process.\n\nBecause method runs in separate process you can not access the same data in static fields. \nAny change in static data in one process has no effect for other. \nBecause of the same reason any changes made in parameter objects will not be passed to other processes. \nIf you pass one of parameters as result, returned object will be a new object with new reference not related with original parameter.\n\nInstalling\n----------\nTo install from Nuget use.\n```\nInstall-Package ProcessThreads\n```\n\nSimple example\n--------------\n\n```C#\npublic static string TestMethod(int param) // Executed in new process\n{\n    return \"*\" + (param * 10) + \"*\";\n}\n\npublic void StartProcess()\n{\n    var manager = new ProcessThreadsManager();\n    var task = manager.Start(()=\u003eTestMethod(15)); // Returns immediately\n    Console.WriteLine(task.Result); // Waits for result and types *150*\n}\n\n```\n\nOne of library purposes is catching ```StackOverflowException```. It also passes back to ```Task``` any other exceptions if possible.\n\n```C#\npublic static void TestStackOverflowException()\n{\n    TestStackOverflowExceptionException();\n}\n\npublic void StartTestStackOverflowException()\n{\n\tvar manager = new ProcessThreadsManager();\n    var task = manager.Start(()=\u003eTestStackOverflowException());\n\ttry{\n\ttask.Wait();\n\t} catch(AggregateException e)\n\t{\n\t\tConsole.WriteLine(e.InnerException); //Oops, StackOverflowException\n\t}\n}\n\n```\n\nCancellation\n------------\n\n```C#\npublic static void TestCancel()\n{\n    while (!ProcessManager.IsCancelled)\n    {\n        ... //Do something\n    }\n}\n\npublic void StartTestCancel()\n{\n\tvar manager = new ProcessThreadsManager();\n    var task = manager.Start(()=\u003eTestCancel());\n    ... //Do something\n    manager[task].Cancel();\n}\n```\nIn this case ```Task``` will not have ```IsCanceled``` state, but usual ```IsCompleted```\n\nYou also can throw ```OperationCanceledException``` within ProcessThread method, in such case Task will have ```IsCanceled``` state.\nUse ```ProcessManager.ThrowIfCancellationRequested``` to check cancellation and throw ```OperationCanceledException```\n\nPipeStream\n----------\nFor real-time data exchange you can use ```Start``` with ```NamedPipeServerStream ``` out parameter. ```NamedPipeClientStream``` will be passed as Lambda parameter to your method.\nYour code is fully responsible for pipes, including proper closing on both sides.\nDon't forget to call ```WaitForConnection``` on caller side to be sure pipe is connected.\n\n```C#\npublic static void TestPipe(string param, NamedPipeClientStream pipe)\n{\n\t... //Do something\n\tpipe.Close();\n}\n\npublic void StartTestPipe()\n{\n\tvar manager = new ProcessThreadsManager();\n\tNamedPipeServerStream pipe;\n\tmanager.Start((p) =\u003e TestPipe(\"blabla\", p), out pipe);\n    pipe.WaitForConnection();\n\t... //Do something\n\tpipe.Disconnect();\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frambalac%2Fprocessthreads","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frambalac%2Fprocessthreads","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frambalac%2Fprocessthreads/lists"}