I have a question for the community. I am sure you are starting to get a lot of questions like these. Before I ask, let me explain my situation.
I work in an environment where compiled code is restricted and it takes an act of god to get a new application introduced into the production environment. Scripts however, are all fair game. I have found the need to parse account requests from PDF files to better handle the account creation process. In a perfect world, we would be using a pure Microsoft environment where I can fully automate the account creation process. Unfortunately, the the several accounts that I create are from a Solaris platform. I have, however, used Powershell (on a different system that is also at my work space) to create a Windows Forms application in combination with iTextSharp to drag the account request PDFs from either Outlook or another location on the system’s drive to automatically populate a DataGridView with the important information that I use to create these accounts. At first glance, this may seem like overkill, however, 1 user’s account request form can indicate a new account on up to 15 different Solaris applications. Thus, I found a need to be able to sort data on a real-time basis when creating these accounts.
That is the background information. The problem I have is sometimes we get 30 user account creation PDF’s at a time. I handle these in my application with a ForEach Loop, however the actual parsing function takes about 5-10 seconds sometimes to populate the DataGridView per each user. Importing a large amount of requests like this can sometimes freeze the application. Here comes my question.
Is is possible to populate a DataGridView with multithreading all using the same memory space?
Here is a simple example of what I am trying to do:
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$Main = New-Object Windows.Forms.Form
$Main.Width = 1024
$Main.Height = 768
$ScriptBlock = `
{
# This Start-Sleep command is a representation of the amount of time it takes to parse the PDF data.
Start-Sleep -Seconds 5
$DataGrid.Rows.Add(“This is my test Name.”,“This is my test value.”)
}
$Button = New-Object Windows.Forms.Button
$Button.Location = New-Object Drawing.Point(0,708)
$Button.Size = New-Object Drawing.Size(1010,24)
$Button.Anchor = “Left,Right,Bottom”
$Button.Text = ‘Add Row (This Button is a representation of dropping a PDF account request into this window.)’
Preferably, I would like the button click to execute my function in a different thread, but still populate the $DataGrid with the results.
$Button.Add_Click($ScriptBlock)
$Main.Controls.Add($Button)
$DataGrid = New-Object System.Windows.Forms.DataGridView
$DataGrid.Size = New-Object Drawing.Size(1010,708)
$DataGrid.Anchor = “Top,Left,Right,Bottom”
$DataGrid.ColumnCount = 2
$DataGrid.Columns[0].Name = “Name”
$DataGrid.Columns[1].Name = “Value”
$Main.Controls.Add($DataGrid)