0

Actual code showing what the basic is code is supposed to look like

Reference: Runspace for button event in powershell https://www.foxdeploy.com/blog/part-v-powershell-guis-responsive-apps-with-progress-bars.html So, I believe my issue is that PowerShell is unable to access the memory space of the file system, from within the memory block, of my thread, is there a way to solve this, to access the file system, from a multi-threaded application? Back Story: So, I run a program, that calls upon "code"/command, from the command prompt, (*.exe) (Robocopy) to copy files from a server, to a group of computers, at a time. We have a classroom environment, at my work, so I have my setup, in a way, that I have a folder, per room. I keep a list of all our addresses (static), for each room, in their perspective folders. We have an update, from our developers, that we need to push to all of the rooms. We need to run a slow push, as to not disturb the production environment. It's proprietary, so we can't use a/any typical solution(s), like Microsoft SCCM. So, I created a script to push to the rooms. while it does work, it's not a smooth operation. I'm not actually the one pushing the update, because of the slow process, of updating. I'm just trying to make a stable smooth-running package, for the person, who is going to be doing it. My code works, outside of the thread, (I) tested it, I know it works. So how I came my conclusion of knowing, that my code works outside of the thread. (The picture) I followed the same setup, with my code, (A button click event inside of a thread, running the form). Placed the actual working code, (tried, and tested, before making a Thread, for the interface, after completing backend operation code testing.) ("Region Boe's Addition") referring to Boe Prox, (from the link) In his, he is updating from a command line/powershell window, via a function run inside a thread. I'm running an event from a button, inside of a thread and trying to run a separate thread, for the click event(s). Outside of the thread. The event works fine, but inside, it doesn't work, at all.. Basic Code:

   // Multi thread, thread for the $form, and thread for the event (as per referenced link)
   $var = [PowerShell]::Create().AddScript({ button.Add_Click{
       $var = [PowerShell]::Create().AddScript{<Thread><Robocopy></Thread>}
   })
7
  • There is no obvious reason why another thread shouldn't have file-system access. Please update your question to describe the specific symptom that led you to this conclusion, and what you mean by memory space of the file system. Commented Jun 27, 2022 at 18:22
  • I just meant the basic operations of a computer system, when you boot into Windows, and it loads, the contents of your hard drive, into the RAM, "Memory space". Threads, obviously, creating memory blocks, if something is outside of that memory address, how do you access it, in code, with powershell.. Lol. Commented Jun 27, 2022 at 19:47
  • So, my reference "stackoverflow.com/questions/72724246/…", has a picture, showing the actual code, of my basic code, with button click event with the thread inside of it. Now, I don't need the thread inside of it, if.. it doesn't matter, I was just following some blog, trying to figure out how Threads work.. Lol. If the form requires it's own thread, in order to operate a button, within the same memory block, so be it, but I basically just need a button to run a thread, outside of the memory space/block of the executing program. Commented Jun 27, 2022 at 19:53
  • If the form requires it's own thread, in order to operate a button, within the same memory block, so be it, but I basically just need a button to run a thread, outside of the memory space/block of the executing program, as to not "kill"/freeze/crash my program, during operation. Commented Jun 27, 2022 at 19:54
  • 1
    Honestly, it doesn't help much. There is now a lot of incidental information in a wall of text, and the specifics of your problem are still unclear. The code snippet at the end is confusing, and it's unclear why you're trying to attach a button-event handler from a parallel runspace and are then attempting to create a nested runspace, which is probably not a good idea. Again, the code you were given in this answer is a better starting point. Commented Jun 28, 2022 at 15:56

1 Answer 1

0

Needed the "Start-Process" -Wait command to allow for the listbox, to be updated in-between copies, to confirm installation, through each step in the loop.

    $choice = $comboBox.SelectedItem
    # $drive = Get-Location
    if(!(Test-Path -PathType Container -Path "L:\$choice"))
    {
#        New-Item -ItemType "container" -Path . -Name $choice
        New-Item -ItemType "Directory" -Path . -Name $choice
    }

#        $folder = $_
        # Where is it being stored at?
        [System.IO.File]::ReadLines("Y:\$choice\IPs.txt") | foreach {
            ping -a -n 2 -w 2000 $_ | Out-Null
            Test-Connection -Count 2 -TimeToLive 2 $_ | Out-Null

            if($?)
            {
               RoboCopy /Log:"L:\$folder\$_.log" $source \\$_\c$\tools
               RoboCopy /Log+:"L:\$folder\$folder-MovementLogs.log" $source \\$_\c$\tools
               Start-Process -Wait "P:\psexec.exe" -ArgumentList "\\$_ -d -e -h -s cmd /c reg import C:\tools\dump.reg"
               # Copy-Item -LiteralPath Y:\* -Destination \\$_\c$\tools
               $listBox.Items.Add($_)
            }
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.