Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class SafeHandlesExample
{
static void Main()
{
UnmanagedMutex uMutex = new UnmanagedMutex("YourCompanyName_SafeHandlesExample_MUTEX");
UnmanagedMutex uMutex = new("YourCompanyName_SafeHandlesExample_MUTEX");

try
{
Expand All @@ -22,49 +22,43 @@ static void Main()
finally
{
uMutex.Release();
Console.WriteLine("Mutex Released.");
Console.WriteLine("Mutex released.");
}

Console.ReadLine();
}
}

class UnmanagedMutex
partial class UnmanagedMutex(string Name)
{

// Use interop to call the CreateMutex function.
// For more information about CreateMutex,
// see the unmanaged MSDN reference library.
[DllImport("kernel32.dll", CharSet=CharSet.Unicode)]
static extern SafeWaitHandle CreateMutex(IntPtr lpMutexAttributes, bool bInitialOwner,
string lpName);
[LibraryImport("kernel32.dll", EntryPoint = "CreateMutexW", StringMarshalling = StringMarshalling.Utf16)]
private static partial SafeWaitHandle CreateMutex(
IntPtr lpMutexAttributes,
[MarshalAs(UnmanagedType.Bool)] bool bInitialOwner,
string lpName
);

// Use interop to call the ReleaseMutex function.
// For more information about ReleaseMutex,
// see the unmanaged MSDN reference library.
[DllImport("kernel32.dll")]
public static extern bool ReleaseMutex(SafeWaitHandle hMutex);
[LibraryImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool ReleaseMutex(SafeWaitHandle hMutex);

private SafeWaitHandle handleValue = null;
private IntPtr mutexAttrValue = IntPtr.Zero;
private string nameValue = null;

public UnmanagedMutex(string Name)
{
nameValue = Name;
}
private SafeWaitHandle _handleValue = null;
private readonly IntPtr _mutexAttrValue = IntPtr.Zero;
private string nameValue = Name;

public void Create()
{
ArgumentException.ThrowIfNullOrEmpty(nameValue);

handleValue = CreateMutex(mutexAttrValue,
_handleValue = CreateMutex(_mutexAttrValue,
true, nameValue);

// If the handle is invalid,
// get the last Win32 error
// and throw a Win32Exception.
if (handleValue.IsInvalid)
if (_handleValue.IsInvalid)
{
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
}
Expand All @@ -74,11 +68,9 @@ public SafeWaitHandle Handle
{
get
{
// If the handle is valid,
// return it.
if (!handleValue.IsInvalid)
if (!_handleValue.IsInvalid)
{
return handleValue;
return _handleValue;
}
else
{
Expand All @@ -87,17 +79,11 @@ public SafeWaitHandle Handle
}
}

public string Name
{
get
{
return nameValue;
}
}
public string Name => nameValue;

public void Release()
{
ReleaseMutex(handleValue);
ReleaseMutex(_handleValue);
}
}
//</Snippet1>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</Base>
<Interfaces />
<Docs>
<summary>Implements the <c>GenerateTemporaryTargetAssembly</c> task. Use the <c>GenerateTemporaryTargetAssembly</c> element in your project file to create and execute this task. For usage and parameter information, see [GenerateTemporaryTargetAssembly](/visualstudio/msbuild/generatetemporarytargetassembly-task).</summary>
<summary>Implements the <c>GenerateTemporaryTargetAssembly</c> task. Use the <c>GenerateTemporaryTargetAssembly</c> element in your project file to create and execute this task. For usage and parameter information, see <see href="/visualstudio/msbuild/generatetemporarytargetassembly-task">GenerateTemporaryTargetAssembly</see>.</summary>
<remarks>To be added.</remarks>
<forInternalUseOnly />
</Docs>
Expand Down Expand Up @@ -265,13 +265,13 @@
<value>
<see langword="true" /> if debugging information is enabled for the <see cref="T:Microsoft.Build.Tasks.Windows.GenerateTemporaryTargetAssembly" /> Task; otherwise, <see langword="false" />.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:Microsoft.Build.Tasks.Windows.GenerateTemporaryTargetAssembly.GenerateTemporaryTargetAssemblyDebuggingInformation%2A> property is an optional task parameter. It's a diagnostic parameter, and it defaults to `false`.
The only debugging information that is generated consists of the temporary project that is created to generate the temporary target assembly. The temporary project is normally deleted at the end of the MSBuild task. When <xref:Microsoft.Build.Tasks.Windows.GenerateTemporaryTargetAssembly.GenerateTemporaryTargetAssemblyDebuggingInformation%2A> is enabled, the temporary project is retained for inspection by the developer.
<format type="text/markdown"><![CDATA[

## Remarks
The <xref:Microsoft.Build.Tasks.Windows.GenerateTemporaryTargetAssembly.GenerateTemporaryTargetAssemblyDebuggingInformation%2A> property is an optional task parameter. It's a diagnostic parameter, and it defaults to `false`.

The only debugging information that is generated consists of the temporary project that is created to generate the temporary target assembly. The temporary project is normally deleted at the end of the MSBuild task. When <xref:Microsoft.Build.Tasks.Windows.GenerateTemporaryTargetAssembly.GenerateTemporaryTargetAssemblyDebuggingInformation%2A> is enabled, the temporary project is retained for inspection by the developer.

]]></format>
</remarks>
</Docs>
Expand Down
2 changes: 1 addition & 1 deletion xml/Microsoft.JScript/ErrorType.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</ReturnValue>
<MemberValue>1</MemberValue>
<Docs>
<summary>An [eval Method (Visual Studio - JScript)](/previous-versions/visualstudio/visual-studio-2010/b51a45x6(v=vs.100)) error. Corresponds to the <see cref="T:Microsoft.JScript.EvalErrorObject" /> object.</summary>
<summary>An <see href="/previous-versions/visualstudio/visual-studio-2010/b51a45x6(v=vs.100)">eval Method (Visual Studio - JScript)</see> error. Corresponds to the <see cref="T:Microsoft.JScript.EvalErrorObject" /> object.</summary>
<forInternalUseOnly />
</Docs>
</Member>
Expand Down
2 changes: 1 addition & 1 deletion xml/Microsoft.JScript/EvalErrorObject.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</Base>
<Interfaces />
<Docs>
<summary>Represents an error that occurs when the <see langword="eval" /> method is used. For more information, see [eval Method (Visual Studio - JScript)](/previous-versions/visualstudio/visual-studio-2010/b51a45x6(v=vs.100)).</summary>
<summary>Represents an error that occurs when the <see langword="eval" /> method is used. For more information, see <see href="/previous-versions/visualstudio/visual-studio-2010/b51a45x6(v=vs.100)">eval Method (Visual Studio - JScript)</see>.</summary>
<remarks>To be added.</remarks>
<forInternalUseOnly />
<altmember cref="T:Microsoft.JScript.ErrorType" />
Expand Down
Loading
Loading