multithreading - Share memory between Powershell and C# -
I am developing log search software by C #, and the underwear of the software is obtained by PowerShell. There are two sardards, one thread invokes the PowerShell in the search log, the logshop function is obtained by PowerShell and after implementing PowerShell it will give me results. But I want to get log realtime. I want the parcels to insert the links which have been searched in the queue and to get results from the queue, I have tried to write logs which have got the PowerShell in one file, and the other #thread has read the file. But it has failed, because the file has been captured by another process (powers). Now I want to share the memory between powershell and C #, which means that powershell can operate the C # variable so that I can search the logs for a parcel when entering the line. Can you please tell me how can I get it? Thank you.
You have several options here. First of all, you do not need to use PowerShell's file output command (out-file / set-content). You can use .NET FileStream / StreamWriter classes directly from PowerShell, which allows you to control FileAccess / FileShare options. Second, you can create a ConcurrentQueue (or BlockingCollection) and write it in PowerShell. Thirdly, you can use MSMQ. Fourth, even though I have not tried it personally, I do not know why the functionality of the .net memory map will not work in PowerShell. The last two options look like overkill for me: -)
Comments
Post a Comment