LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I create windows mutexes in LabVIEW?

I need to launch and control an Application written in C from LabVIEW.  The lauching is easy using System Exec.vi but I need to create two Mutexes to control the launched application.  Control is initiated by using a command and a result file to pass commands / results to / from the running application.  The Mutexes protect the shared file resources.

I know that I can NOT create a system mutex from LabVIEW but is it possible using Active-X or .net objects to perform this?  I am a novice when it comes to this.
Visualize the Solution

CLA

LabVIEW, LabVIEW FPGA
Message 1 of 9
(7,432 Views)
 After many hours I have figured out how to create windows mutexex from within LabVIEW.  Smiley Happy

I used the .net constructor to create the mutex - returning a reference to the mutex.  I then use invoke nodes to release, WaitOne, and  Close the mutex.  One caveat I found is that all vis creating or manipulating a mutex must run in the UI thread.

I hope this helps anyone else you needs to perform this task.




Visualize the Solution

CLA

LabVIEW, LabVIEW FPGA
Message 2 of 9
(7,406 Views)

Thanks you Dave!

You have proven yourself worthy of your signature!


VADave
CLA
Using LabVIEW since 1.2


Ben



Message Edited by Ben on 03-06-2008 09:00 AM
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 3 of 9
(7,398 Views)
    Thank You Ben

It just took a lot of persistance and staring at the MSDN site. http://msdn2.microsoft.com/en-us/library/system.threading.mutex_members.aspx

Here is the Mutex handler where in my case I release both mutexes then grab them back.  The Application I am controlling is waiting to grab the mutexes,  therefore when I  release the mutexes the application grabs the mutexes, then I wait for the mutexes to be released.

How do you paste an image into a message?
Visualize the Solution

CLA

LabVIEW, LabVIEW FPGA
Message 4 of 9
(7,386 Views)

First get the URL of your image. If you have not posted it yet, attach it as you did previously

post the reply then click on your attached link and copy the URL

quickly (5 minute limit on edits) return to your post and edit it.

When editing click the "insert an image" button

paste the image URL into dialog box.

submit edited post.

Again, thanks for sharing your findings!

Ben



Message Edited by Ben on 03-06-2008 10:29 AM
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 5 of 9
(7,380 Views)
    Ben

I have found a way to launch an .exe from the .net framework.  The nice thing about this is we now have a handle on the .exe so that we can dispose of it when we are through with it.  There are many more properties and methods available than what I am using here.  I look forward to seeing more uses of this method in the future.


Message Edited by VADave on 03-12-2008 12:08 PM

Message Edited by VADave on 03-12-2008 12:09 PM

Message Edited by VADave on 03-12-2008 12:11 PM
Visualize the Solution

CLA

LabVIEW, LabVIEW FPGA
Message 6 of 9
(7,329 Views)

I see you're setting "exitContext" to true here.  Can you (or anyone) explain why this is necessary (or if it's not), and what it does?

0 Kudos
Message 7 of 9
(5,433 Views)

TimBlaisdell

Please, take a look at these threads with the similar question:

c# - What is the exitContext used for on a WaitHandle.WaitOne method

.net - What does the exit context mean for a WaitHandle.WaitOne mean?

MSDN - WaitHandle.WaitOne Method (TimeSpan, Boolean)

 

Btw I wonder why to tie yourself to .NET and its libraries when there's WinAPI's CreateMutex func and its friends... This should run smoothly in any thread and should be faster than .NET approach.

0 Kudos
Message 8 of 9
(5,426 Views)

I would second the use of the WinAPI functions. Ultimately .Net also uses these kernel objects internally. And since LabVIEW does not generate.Net IL code, there is no real advantage in using the .Net API over the Win32 API, especially since this API is fairly simple to interface (most callers completely ignore the security attributes parameter, which would be fairly complicated to handle correctly).

 

Look at CreateMutex(), WaitForSingleObject(), ReleaseMutex() and CloseHandle() on MSDN.

Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 9
(5,396 Views)