tag:blogger.com,1999:blog-5416778419136716668.post5552107584817635847..comments2023-05-13T08:05:19.390-07:00Comments on LUKE PUPLETT: Ensuring that two PowerShell scripts don't run at the same timeLuke Pupletthttp://www.blogger.com/profile/08367127592060126449noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-5416778419136716668.post-79809887964057414462021-02-02T23:00:16.822-08:002021-02-02T23:00:16.822-08:00https://powershell.org/forums/topic/powershell-mut...https://powershell.org/forums/topic/powershell-mutex-not-working-as-expected/ This code works, but while trying to implement "single instance, exit on mutex not acquired", Close() seems to be better than Dispose()Eddyhttps://www.blogger.com/profile/09776801718913257396noreply@blogger.comtag:blogger.com,1999:blog-5416778419136716668.post-2712918228419346762013-01-24T07:48:42.432-08:002013-01-24T07:48:42.432-08:00Sheeze, I can't type today. was = wasn't a...Sheeze, I can't type today. was = wasn't and like = live.Luke Pupletthttps://www.blogger.com/profile/08367127592060126449noreply@blogger.comtag:blogger.com,1999:blog-5416778419136716668.post-29098689965322719372013-01-24T07:47:28.124-08:002013-01-24T07:47:28.124-08:00Good stuff. Funny, I can't image a world in wh...Good stuff. Funny, I can't image a world in which a Mutex was IDisposable. I don't know if you're a .NET guy but any type that creates kernel objects, or other resources that like outside of .NET, must implement IDisposable (i.e. have a Dispose method). In any case, the Close method will release everything. Cheers Paul.Luke Pupletthttps://www.blogger.com/profile/08367127592060126449noreply@blogger.comtag:blogger.com,1999:blog-5416778419136716668.post-74118959118747685992013-01-24T07:42:53.120-08:002013-01-24T07:42:53.120-08:00Good call, Luke. $mutant.Close() doesn't give ...Good call, Luke. $mutant.Close() doesn't give me the error. My guess is something to do with the version of .NET I'm running.Paul Sandhttps://www.blogger.com/profile/06175388613093409161noreply@blogger.comtag:blogger.com,1999:blog-5416778419136716668.post-37409569325975908432013-01-24T07:29:47.082-08:002013-01-24T07:29:47.082-08:00I'll be honest Paul, I have no idea why! You c...I'll be honest Paul, I have no idea why! You could try Close() instead, it does mostly the same thing.Luke Pupletthttps://www.blogger.com/profile/08367127592060126449noreply@blogger.comtag:blogger.com,1999:blog-5416778419136716668.post-68399196097112892462013-01-24T07:27:31.491-08:002013-01-24T07:27:31.491-08:00When I try to run this, I get "Method invocat...When I try to run this, I get "Method invocation failed because [System.Threading.Mutex] doesn't contain a method named 'Dispose'."Paul Sandhttps://www.blogger.com/profile/06175388613093409161noreply@blogger.comtag:blogger.com,1999:blog-5416778419136716668.post-60627161537127419072013-01-22T03:58:41.431-08:002013-01-22T03:58:41.431-08:00Added ReleaseMutex call before dispose, since disp...Added ReleaseMutex call before dispose, since dispose doesn't seem to release. By design?Luke Pupletthttps://www.blogger.com/profile/08367127592060126449noreply@blogger.com