Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing synchronized hashtable as argument does not work #133

Closed
kborowinski opened this issue Mar 10, 2017 · 4 comments
Closed

Passing synchronized hashtable as argument does not work #133

kborowinski opened this issue Mar 10, 2017 · 4 comments
Assignees

Comments

@kborowinski
Copy link
Contributor

kborowinski commented Mar 10, 2017

I would like to reopen issue #45 as passing synchronized hashtable as argument does not work.
Update: I guess this behaviour may be related to issue #132.

This does not work:

$hash = [hashtable]::Synchronized(@{Number=0})
$sb = {
	param($syncHash)
	[System.Threading.Monitor]::Enter($syncHash.SyncRoot)
	$syncHash.Number += 10
	[System.Threading.Monitor]::Exit($syncHash.SyncRoot)
}
1..10 | Start-RSJob -Name {$_} -ScriptBlock $sb -ArgumentList $hash | Wait-RSJob | Receive-RSJob

Error:

Exception calling "Enter" with "1" argument(s): "Value cannot be null."
The property 'Number' cannot be found on this object. Verify that the property exists and can be set.
Exception calling "Exit" with "1" argument(s): "Value cannot be null."
...

This works perfectly:

$hash = [hashtable]::Synchronized(@{Number=0})
$sb = {
	($using:hash).Number += 10
}
1..10 | Start-RSJob -Name {$_} -ScriptBlock $sb | Wait-RSJob | Receive-RSJob

Components:
Powershell 5.0
PoshRSJob 1.7.3.7

@jgmmi
Copy link

jgmmi commented Mar 13, 2017

I would like to indicate that this problem exists for me in PoshRSJob 1.7.3.7 and PowerShell 5.1 (WMF 5.1).

For now, I'm using PoshRSJob 1.7.3.3 without problems.

@proxb proxb added the bug label Mar 13, 2017
@proxb
Copy link
Owner

proxb commented Mar 13, 2017

Interesting, I will look at 1.7.3.3 and see what differences there are with the code.

@proxb
Copy link
Owner

proxb commented Mar 15, 2017

I found the offending line of code that is causing this to break. It appears that one of the PRs that came through made an update that broke this. It is directly related to #132

@proxb proxb self-assigned this Mar 17, 2017
@proxb proxb added the Ready label Mar 17, 2017
@proxb
Copy link
Owner

proxb commented Apr 3, 2017

This should be fixed in the latest release

@proxb proxb closed this as completed Apr 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants