Please enable JavaScript to view this site.

thinBasic Help Manual

* * HELP & MANUAL PREMIUM PACK 4 DEMO VERSION * *

This documentation was styled with a demo skin from the Premium Pack 4 add-on for Help & Manual. The contents of the skin are encrypted and not configurable. You can only publish HM projects with this skin. You cannot edit it or change it.

This version is copyright and may only be used for local testing purposes. It may not be distributed.

Please purchase the full version of the Premium Pack to get the configurable skins and remove this notice. The package will also include the Toolbox configuration utility for Premium Pack skins.

 

Description

 

Create a unique mutex returning its handle.

 

Syntax

 

Mutex_Handle = APP_MutexCreate(AUniqueMutexName)

 

Returns

 

Number

If Zero it can mean either that a mutex with the same name already exists or current user has no enough authorization to create a mutex.

 

Parameters

 

Name

Type

Optional

Meaning

AUniqueMutexName

String

No

A mutex name.

 

Remarks

 

The Mutex object is a synchronization objects. Its basic purpose is to provide a synchronization method. For example if you want to be sure that a script is executed just once, try to create a mutex with a unique name. If you cannot create a mutex with that name (return value is zero), it can mean the same script is already running in your system so stop current one. If instead you can create a mutex, it means the same script is not running.

 

It is important to store returned handle in order to be able, later, to close it.

It is programmer responsibility to close all created mutex.

If return value is zero it can mean either that a mutex with the same name already exists or current user has no enough authorization to create a mutex.

 

Restrictions

 

See also

 

App Object, App_MutexClose,

 

Examples

 

Dim hMutex      As DWORD

Dim Mutex_Name  As String = "AVeryUniqueStringToNameMutex"

 

'---Better if MutexName has script name inside so it will be specific to this script

Mutex_Name += app_scriptname

 

hMutex = APP_MutexCreate(Mutex_Name)

 

If hMutex = 0 Then

  MSGBOX 0, _

            "I was not able to create a Mutex named: " & Mutex_Name & $crlf & _

            "This means that another instance of the same script is already running" & $crlf & _

            "or you have not enough user authorization to create a Mutex." & $crlf & _

            "In any case script execution is aborted. Sorry"%MB_ICONERROR

  STOP

Else

  MSGBOX 0, _

            "I was able to create a Mutex named: " & Mutex_Name & $crlf & _

            "Mutex handle is " & hMutex & "" & $crlf & _

            "Script will continue. Perfect"%MB_ICONINFORMATION

 

End If

 

'...

'------

'---Here code for script ...

'---

'...

 

'---At the end close the mutex handle to release it for new script execution

APP_MutexClose(hMutex)

Created with Help+Manual 8 and styled with Premium Pack Version 4 © by EC Software