WinForm Single Instance App errors out with AccessViolationException

J

J. Clay

I have a couple of windows form applications that I am wanting to integrate
and have been playing around with the Single Instance Application setting.
I have tried this with my own app and the sample SingleInstance05 that I got
from MSDN. I can run it, but if I go to a cmd console and go to the bin
directory and try and run the app again to trigger the SingleInstance
functionality, I get a System.AccessViolationException of

{"Attempted to read or write protected memory. This is often an indication
that other memory is corrupt."}

The stackTrace is as follows:

at
System.Net.UnsafeNclNativeMethods.OSSOCK.WSAGetOverlappedResult(SafeCloseSocket
socketHandle, IntPtr overlapped, UInt32& bytesTransferred, Boolean wait,
IntPtr ignored)
at
System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

Any suggestions?

TIA,
J. Clay
 
L

Linda Liu [MSFT]

Hi J.Clay,

Thank you for posting.

I don't know what sample you are trying with your application. But I will
give you a sample code that makes use of the Mutex class in
System.Threading namespace.

using System.Threading;

public class Form1:Form
{
private void Form1_Load(object sender, EventArgs e)
{
Boolean requestInitialOwnership = true;
Boolean mutexWasCreated = false;

Mutex mut = new Mutex(requestInitialOwnership,
"MSFMSGUI_MUTEX",out mutexWasCreated);
if (!mutexWasCreated)
{
this.Close();
}
}
}

Hope this helps.
If you have anything unclear, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

============================================================================
=============================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

With newsgroups, MSDN subscribers enjoy unlimited, free support as opposed
to the limited number of phone-based technical support incidents. Complex
issues or server-down situations are not recommended for the newsgroups.
Issues of this nature are best handled working with a Microsoft Support
Engineer using one of your phone-based incidents.

============================================================================
=============================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
L

Linda Liu [MSFT]

Hi J. Clay,

I am closely monitoring the newsgroup and I am contacting you to check the
issue status.

If the problem is not resolved or you have anything unclear, please feel
free to post in the newsgroup and we will follow up.

Thank you for using our MSDN Managed Newsgroup Support Service!


Sincerely,
Linda Liu
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top