473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Semaphores and .NET

I have a C# application and a VB6 application that need to share a dialup
connection to the internet. Don't ask why, this is one of those corporate "do
or die" things.

The only way I can see to do this is by using the combination of a MUTEX to
create a Cross-application Singleton for the Dialing operation and a Named
Semphore that can keep a count of how many processes are currently sharing
the connection from the client's workstation into our corporate VPN extranet.
I am trying to find an example of how to manage semaphores in C# in a class.
I will have to translate the same into the VB6 for the legacy app.

Using .NET 2.0 is not an option, they won't let me use a BETA. Neither is
remoting. I have to make the access sharable between executables modules.
Does any one have any ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

Nov 17 '05 #1
34 6257
Maybe this link would be helpful to you
http://weblogs.asp.net/tspascoal/arc.../16/59340.aspx

Sincerely,
Bobby

Nov 17 '05 #2
Bobby;

Again, I don't think any one understands that these are 2 spearate
executables. Monitor won't do it. It has to be something similar to MUTEX but
will allow a certain number of executables to share the Connection to the
internet and will prevent which ever one completes first from hanging up on
the second one. The MUTEX would only prevent one from dialing while the other
one is dialing. The Semaphore tracks how many active transfers are going on
simultaneously.

Please any more ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"bo*********@gmail.com" wrote:
Maybe this link would be helpful to you
http://weblogs.asp.net/tspascoal/arc.../16/59340.aspx

Sincerely,
Bobby

Nov 17 '05 #3
A week ago, I posted a sample implementation of semaphore using Win32 API.
This solution can be adjusted so the semaphore handle can be shared among
processes, which will suit your needs, if I understand what you need to
accomplish.
This is were the implementation is posted
http://www.pcreview.co.uk/forums/pri....php?t=2099193
have a look at MSDN for settings you need to change when handle should be
shared among processes.
"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
Bobby;

Again, I don't think any one understands that these are 2 spearate
executables. Monitor won't do it. It has to be something similar to MUTEX but will allow a certain number of executables to share the Connection to the
internet and will prevent which ever one completes first from hanging up on the second one. The MUTEX would only prevent one from dialing while the other one is dialing. The Semaphore tracks how many active transfers are going on simultaneously.

Please any more ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"bo*********@gmail.com" wrote:
Maybe this link would be helpful to you
http://weblogs.asp.net/tspascoal/arc.../16/59340.aspx

Sincerely,
Bobby

Nov 17 '05 #4
Bobby;

Again, I don't think any one understands that these are 2 spearate
executables. Monitor won't do it. It has to be something similar to MUTEX but
will allow a certain number of executables to share the Connection to the
internet and will prevent which ever one completes first from hanging up on
the second one. The MUTEX would only prevent one from dialing while the other
one is dialing. The Semaphore tracks how many active transfers are going on
simultaneously.

Please any more ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"bo*********@gmail.com" wrote:
Maybe this link would be helpful to you
http://weblogs.asp.net/tspascoal/arc.../16/59340.aspx

Sincerely,
Bobby

Nov 17 '05 #5
A week ago, I posted a sample implementation of semaphore using Win32 API.
This solution can be adjusted so the semaphore handle can be shared among
processes, which will suit your needs, if I understand what you need to
accomplish.
This is were the implementation is posted
http://www.pcreview.co.uk/forums/pri....php?t=2099193
have a look at MSDN for settings you need to change when handle should be
shared among processes.
"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
Bobby;

Again, I don't think any one understands that these are 2 spearate
executables. Monitor won't do it. It has to be something similar to MUTEX but will allow a certain number of executables to share the Connection to the
internet and will prevent which ever one completes first from hanging up on the second one. The MUTEX would only prevent one from dialing while the other one is dialing. The Semaphore tracks how many active transfers are going on simultaneously.

Please any more ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"bo*********@gmail.com" wrote:
Maybe this link would be helpful to you
http://weblogs.asp.net/tspascoal/arc.../16/59340.aspx

Sincerely,
Bobby

Nov 17 '05 #6
I guess you should consider me dumb as dirt, because I can't see how I can
implement this in such a way that all processes will have access to the same
named semaphore when the only constructor that implements the name is
protected in your example. I am not being factious, I just don't understand.
Most of this is brand new to me and I seem to keep getting thrown the
projects that would even give MSDN MVP's pause for thought.

Would you please explain this a little further, Lebesgue, so that even a
clod like me could understand.

Thanks.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"Lebesgue" wrote:
A week ago, I posted a sample implementation of semaphore using Win32 API.
This solution can be adjusted so the semaphore handle can be shared among
processes, which will suit your needs, if I understand what you need to
accomplish.
This is were the implementation is posted
http://www.pcreview.co.uk/forums/pri....php?t=2099193
have a look at MSDN for settings you need to change when handle should be
shared among processes.
"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
Bobby;

Again, I don't think any one understands that these are 2 spearate
executables. Monitor won't do it. It has to be something similar to MUTEX

but
will allow a certain number of executables to share the Connection to the
internet and will prevent which ever one completes first from hanging up

on
the second one. The MUTEX would only prevent one from dialing while the

other
one is dialing. The Semaphore tracks how many active transfers are going

on
simultaneously.

Please any more ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"bo*********@gmail.com" wrote:
Maybe this link would be helpful to you
http://weblogs.asp.net/tspascoal/arc.../16/59340.aspx

Sincerely,
Bobby


Nov 17 '05 #7
I guess you should consider me dumb as dirt, because I can't see how I can
implement this in such a way that all processes will have access to the same
named semaphore when the only constructor that implements the name is
protected in your example. I am not being factious, I just don't understand.
Most of this is brand new to me and I seem to keep getting thrown the
projects that would even give MSDN MVP's pause for thought.

Would you please explain this a little further, Lebesgue, so that even a
clod like me could understand.

Thanks.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"Lebesgue" wrote:
A week ago, I posted a sample implementation of semaphore using Win32 API.
This solution can be adjusted so the semaphore handle can be shared among
processes, which will suit your needs, if I understand what you need to
accomplish.
This is were the implementation is posted
http://www.pcreview.co.uk/forums/pri....php?t=2099193
have a look at MSDN for settings you need to change when handle should be
shared among processes.
"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
Bobby;

Again, I don't think any one understands that these are 2 spearate
executables. Monitor won't do it. It has to be something similar to MUTEX

but
will allow a certain number of executables to share the Connection to the
internet and will prevent which ever one completes first from hanging up

on
the second one. The MUTEX would only prevent one from dialing while the

other
one is dialing. The Semaphore tracks how many active transfers are going

on
simultaneously.

Please any more ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"bo*********@gmail.com" wrote:
Maybe this link would be helpful to you
http://weblogs.asp.net/tspascoal/arc.../16/59340.aspx

Sincerely,
Bobby


Nov 17 '05 #8
I guess you should consider me dumb as dirt, because I can't see how I can
implement this in such a way that all processes will have access to the same
named semaphore when the only constructor that implements the name is
protected in your example. I am not being factious, I just don't understand.
Most of this is brand new to me and I seem to keep getting thrown the
projects that would even give MSDN MVP's pause for thought.

Would you please explain this a little further, Lebesgue, so that even a
clod like me could understand.

Thanks.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"Lebesgue" wrote:
A week ago, I posted a sample implementation of semaphore using Win32 API.
This solution can be adjusted so the semaphore handle can be shared among
processes, which will suit your needs, if I understand what you need to
accomplish.
This is were the implementation is posted
http://www.pcreview.co.uk/forums/pri....php?t=2099193
have a look at MSDN for settings you need to change when handle should be
shared among processes.
"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
Bobby;

Again, I don't think any one understands that these are 2 spearate
executables. Monitor won't do it. It has to be something similar to MUTEX

but
will allow a certain number of executables to share the Connection to the
internet and will prevent which ever one completes first from hanging up

on
the second one. The MUTEX would only prevent one from dialing while the

other
one is dialing. The Semaphore tracks how many active transfers are going

on
simultaneously.

Please any more ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"bo*********@gmail.com" wrote:
Maybe this link would be helpful to you
http://weblogs.asp.net/tspascoal/arc.../16/59340.aspx

Sincerely,
Bobby


Nov 17 '05 #9
I guess you should consider me dumb as dirt, because I can't see how I can
implement this in such a way that all processes will have access to the same
named semaphore when the only constructor that implements the name is
protected in your example. I am not being factious, I just don't understand.
Most of this is brand new to me and I seem to keep getting thrown the
projects that would even give MSDN MVP's pause for thought.

Would you please explain this a little further, Lebesgue, so that even a
clod like me could understand.

Thanks.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"Lebesgue" wrote:
A week ago, I posted a sample implementation of semaphore using Win32 API.
This solution can be adjusted so the semaphore handle can be shared among
processes, which will suit your needs, if I understand what you need to
accomplish.
This is were the implementation is posted
http://www.pcreview.co.uk/forums/pri....php?t=2099193
have a look at MSDN for settings you need to change when handle should be
shared among processes.
"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
Bobby;

Again, I don't think any one understands that these are 2 spearate
executables. Monitor won't do it. It has to be something similar to MUTEX

but
will allow a certain number of executables to share the Connection to the
internet and will prevent which ever one completes first from hanging up

on
the second one. The MUTEX would only prevent one from dialing while the

other
one is dialing. The Semaphore tracks how many active transfers are going

on
simultaneously.

Please any more ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"bo*********@gmail.com" wrote:
Maybe this link would be helpful to you
http://weblogs.asp.net/tspascoal/arc.../16/59340.aspx

Sincerely,
Bobby


Nov 17 '05 #10
I guess you should consider me dumb as dirt, because I can't see how I can
implement this in such a way that all processes will have access to the same
named semaphore when the only constructor that implements the name is
protected in your example. I am not being factious, I just don't understand.
Most of this is brand new to me and I seem to keep getting thrown the
projects that would even give MSDN MVP's pause for thought.

Would you please explain this a little further, Lebesgue, so that even a
clod like me could understand.

Thanks.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"Lebesgue" wrote:
A week ago, I posted a sample implementation of semaphore using Win32 API.
This solution can be adjusted so the semaphore handle can be shared among
processes, which will suit your needs, if I understand what you need to
accomplish.
This is were the implementation is posted
http://www.pcreview.co.uk/forums/pri....php?t=2099193
have a look at MSDN for settings you need to change when handle should be
shared among processes.
"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
Bobby;

Again, I don't think any one understands that these are 2 spearate
executables. Monitor won't do it. It has to be something similar to MUTEX

but
will allow a certain number of executables to share the Connection to the
internet and will prevent which ever one completes first from hanging up

on
the second one. The MUTEX would only prevent one from dialing while the

other
one is dialing. The Semaphore tracks how many active transfers are going

on
simultaneously.

Please any more ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"bo*********@gmail.com" wrote:
Maybe this link would be helpful to you
http://weblogs.asp.net/tspascoal/arc.../16/59340.aspx

Sincerely,
Bobby


Nov 17 '05 #11
Hi Kenneth!
I am sorry for possible confusion, but I just realized that semaphore
objects can be only inherited among processes, not shared across the whole
system.
I just didn't remember well the thing about SECURITY_ATTRIBUTES mentioned
here
http://msdn.microsoft.com/library/de...esemaphore.asp

"SECURITY_ATTRIBUTES structure that determines whether the returned handle
can be inherited by child processes"

Again, I apologize for confusion.

"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
I guess you should consider me dumb as dirt, because I can't see how I can
implement this in such a way that all processes will have access to the same named semaphore when the only constructor that implements the name is
protected in your example. I am not being factious, I just don't understand. Most of this is brand new to me and I seem to keep getting thrown the
projects that would even give MSDN MVP's pause for thought.

Would you please explain this a little further, Lebesgue, so that even a
clod like me could understand.

Thanks.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"Lebesgue" wrote:
A week ago, I posted a sample implementation of semaphore using Win32 API. This solution can be adjusted so the semaphore handle can be shared among processes, which will suit your needs, if I understand what you need to
accomplish.
This is were the implementation is posted
http://www.pcreview.co.uk/forums/pri....php?t=2099193
have a look at MSDN for settings you need to change when handle should be shared among processes.
"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
Bobby;

Again, I don't think any one understands that these are 2 spearate
executables. Monitor won't do it. It has to be something similar to MUTEX
but
will allow a certain number of executables to share the Connection to
the internet and will prevent which ever one completes first from hanging

up on
the second one. The MUTEX would only prevent one from dialing while
the other
one is dialing. The Semaphore tracks how many active transfers are
going on
simultaneously.

Please any more ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"bo*********@gmail.com" wrote:

> Maybe this link would be helpful to you
> http://weblogs.asp.net/tspascoal/arc.../16/59340.aspx
>
> Sincerely,
> Bobby
>
>


Nov 17 '05 #12
I guess you should consider me dumb as dirt, because I can't see how I can
implement this in such a way that all processes will have access to the same
named semaphore when the only constructor that implements the name is
protected in your example. I am not being factious, I just don't understand.
Most of this is brand new to me and I seem to keep getting thrown the
projects that would even give MSDN MVP's pause for thought.

Would you please explain this a little further, Lebesgue, so that even a
clod like me could understand.

Thanks.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"Lebesgue" wrote:
A week ago, I posted a sample implementation of semaphore using Win32 API.
This solution can be adjusted so the semaphore handle can be shared among
processes, which will suit your needs, if I understand what you need to
accomplish.
This is were the implementation is posted
http://www.pcreview.co.uk/forums/pri....php?t=2099193
have a look at MSDN for settings you need to change when handle should be
shared among processes.
"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
Bobby;

Again, I don't think any one understands that these are 2 spearate
executables. Monitor won't do it. It has to be something similar to MUTEX

but
will allow a certain number of executables to share the Connection to the
internet and will prevent which ever one completes first from hanging up

on
the second one. The MUTEX would only prevent one from dialing while the

other
one is dialing. The Semaphore tracks how many active transfers are going

on
simultaneously.

Please any more ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"bo*********@gmail.com" wrote:
Maybe this link would be helpful to you
http://weblogs.asp.net/tspascoal/arc.../16/59340.aspx

Sincerely,
Bobby


Nov 17 '05 #13
I just got an idea how one would be able to accomplish this, maybe...

I thought of creating a file, using a Mutex to serialize writes to it and
write a single byte when you would be acquiring semaphore and deleting the
last byte when releasing it with checks and possibly a pooling mechanism
used as waiting for semaphore to be signalled (reading that file at
periodical intervals).
Maybe someone will find this like a dumb idea, but at the moment I don't see
a reason why this wouldn't work, and when you have no other possibility,
even a dumb solution is better than no at all.

Just my idea, hope it can be helpful

"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
Bobby;

Again, I don't think any one understands that these are 2 spearate
executables. Monitor won't do it. It has to be something similar to MUTEX but will allow a certain number of executables to share the Connection to the
internet and will prevent which ever one completes first from hanging up on the second one. The MUTEX would only prevent one from dialing while the other one is dialing. The Semaphore tracks how many active transfers are going on simultaneously.

Please any more ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"bo*********@gmail.com" wrote:
Maybe this link would be helpful to you
http://weblogs.asp.net/tspascoal/arc.../16/59340.aspx

Sincerely,
Bobby

Nov 17 '05 #14
jinksk wrote:
Again, I don't think any one understands that these are 2 spearate
executables. Monitor won't do it. It has to be something similar to
MUTEX but will allow a certain number of executables to share the
Connection to the internet and will prevent which ever one completes
first from hanging up on the second one. The MUTEX would only prevent
one from dialing while the other one is dialing. The Semaphore tracks
how many active transfers are going on simultaneously.


I have some code here which may help. Honestly, I don't remember testing
this, I threw it together because I thought I needed it and decided to do
something different. Sorry if it doesn't work.

namespace System.Threading
{
using System;
using System.Threading;
using System.Runtime.CompilerServices;

public sealed class Semaphore : WaitHandle
{

public Semaphore(long initialCount, long maximumCount, String
name, out bool createdNew)
{
IntPtr semaphoreHandle = CreateSemaphoreNative(initialCount,
maximumCount, name, out createdNew); // throws a Win32 exception if
failed to create a semaphore
Handle = semaphoreHandle;
}
public Semaphore(long initialCount, long maximumCount, String
name)
{
bool createdNew;
IntPtr semaphoreHandle = CreateSemaphoreNative(initialCount,
maximumCount, name, out createdNew); // throws a Win32 exception if
failed to create a semaphore
Handle = semaphoreHandle;
}
public Semaphore(long initialCount, long maximumCount)
{
bool createdNew;
IntPtr semaphoreHandle = CreateSemaphoreNative(initialCount,
maximumCount, null, out createdNew); // throws a Win32 exception if
failed to create a semaphore
Handle = semaphoreHandle;
}
public Semaphore(long maximumCount)
{
bool createdNew;
IntPtr semaphoreHandle = CreateSemaphoreNative(0,
maximumCount, null, out createdNew); // throws a Win32 exception if
failed to create a semaphore
Handle = semaphoreHandle;
}

public void ReleaseSemaphore(long releaseCount, out long
previousCount)
{
ReleaseSemaphoreNative(Handle, releaseCount, out
previousCount);
}

public void ReleaseSemaphore(long releaseCount)
{
long previousCount;
ReleaseSemaphoreNative(Handle, releaseCount, out
previousCount);
}

public void ReleaseSemaphore()
{
long previousCount;
ReleaseSemaphoreNative(Handle, 1, out previousCount);
}

[MethodImplAttribute(MethodImplOptions.InternalCall )]
extern private static IntPtr CreateSemaphoreNative(long
initialCount, long maximumCount, String name, out bool createdNew);

[MethodImplAttribute(MethodImplOptions.InternalCall )]
extern private static void ReleaseSemaphoreNative(IntPtr handle,
long releaseCount, out long previousCount);

}
}
--
Reginald Blue
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my
telephone."
- Bjarne Stroustrup (originator of C++) [quoted at the 2003
International Conference on Intelligent User Interfaces]
Nov 17 '05 #15
Hi Kenneth!
I am sorry for possible confusion, but I just realized that semaphore
objects can be only inherited among processes, not shared across the whole
system.
I just didn't remember well the thing about SECURITY_ATTRIBUTES mentioned
here
http://msdn.microsoft.com/library/de...esemaphore.asp

"SECURITY_ATTRIBUTES structure that determines whether the returned handle
can be inherited by child processes"

Again, I apologize for confusion.

"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
I guess you should consider me dumb as dirt, because I can't see how I can
implement this in such a way that all processes will have access to the same named semaphore when the only constructor that implements the name is
protected in your example. I am not being factious, I just don't understand. Most of this is brand new to me and I seem to keep getting thrown the
projects that would even give MSDN MVP's pause for thought.

Would you please explain this a little further, Lebesgue, so that even a
clod like me could understand.

Thanks.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"Lebesgue" wrote:
A week ago, I posted a sample implementation of semaphore using Win32 API. This solution can be adjusted so the semaphore handle can be shared among processes, which will suit your needs, if I understand what you need to
accomplish.
This is were the implementation is posted
http://www.pcreview.co.uk/forums/pri....php?t=2099193
have a look at MSDN for settings you need to change when handle should be shared among processes.
"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
Bobby;

Again, I don't think any one understands that these are 2 spearate
executables. Monitor won't do it. It has to be something similar to MUTEX
but
will allow a certain number of executables to share the Connection to
the internet and will prevent which ever one completes first from hanging

up on
the second one. The MUTEX would only prevent one from dialing while
the other
one is dialing. The Semaphore tracks how many active transfers are
going on
simultaneously.

Please any more ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"bo*********@gmail.com" wrote:

> Maybe this link would be helpful to you
> http://weblogs.asp.net/tspascoal/arc.../16/59340.aspx
>
> Sincerely,
> Bobby
>
>


Nov 17 '05 #16
I just got an idea how one would be able to accomplish this, maybe...

I thought of creating a file, using a Mutex to serialize writes to it and
write a single byte when you would be acquiring semaphore and deleting the
last byte when releasing it with checks and possibly a pooling mechanism
used as waiting for semaphore to be signalled (reading that file at
periodical intervals).
Maybe someone will find this like a dumb idea, but at the moment I don't see
a reason why this wouldn't work, and when you have no other possibility,
even a dumb solution is better than no at all.

Just my idea, hope it can be helpful

"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
Bobby;

Again, I don't think any one understands that these are 2 spearate
executables. Monitor won't do it. It has to be something similar to MUTEX but will allow a certain number of executables to share the Connection to the
internet and will prevent which ever one completes first from hanging up on the second one. The MUTEX would only prevent one from dialing while the other one is dialing. The Semaphore tracks how many active transfers are going on simultaneously.

Please any more ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"bo*********@gmail.com" wrote:
Maybe this link would be helpful to you
http://weblogs.asp.net/tspascoal/arc.../16/59340.aspx

Sincerely,
Bobby

Nov 17 '05 #17
jinksk wrote:
Again, I don't think any one understands that these are 2 spearate
executables. Monitor won't do it. It has to be something similar to
MUTEX but will allow a certain number of executables to share the
Connection to the internet and will prevent which ever one completes
first from hanging up on the second one. The MUTEX would only prevent
one from dialing while the other one is dialing. The Semaphore tracks
how many active transfers are going on simultaneously.


I have some code here which may help. Honestly, I don't remember testing
this, I threw it together because I thought I needed it and decided to do
something different. Sorry if it doesn't work.

namespace System.Threading
{
using System;
using System.Threading;
using System.Runtime.CompilerServices;

public sealed class Semaphore : WaitHandle
{

public Semaphore(long initialCount, long maximumCount, String
name, out bool createdNew)
{
IntPtr semaphoreHandle = CreateSemaphoreNative(initialCount,
maximumCount, name, out createdNew); // throws a Win32 exception if
failed to create a semaphore
Handle = semaphoreHandle;
}
public Semaphore(long initialCount, long maximumCount, String
name)
{
bool createdNew;
IntPtr semaphoreHandle = CreateSemaphoreNative(initialCount,
maximumCount, name, out createdNew); // throws a Win32 exception if
failed to create a semaphore
Handle = semaphoreHandle;
}
public Semaphore(long initialCount, long maximumCount)
{
bool createdNew;
IntPtr semaphoreHandle = CreateSemaphoreNative(initialCount,
maximumCount, null, out createdNew); // throws a Win32 exception if
failed to create a semaphore
Handle = semaphoreHandle;
}
public Semaphore(long maximumCount)
{
bool createdNew;
IntPtr semaphoreHandle = CreateSemaphoreNative(0,
maximumCount, null, out createdNew); // throws a Win32 exception if
failed to create a semaphore
Handle = semaphoreHandle;
}

public void ReleaseSemaphore(long releaseCount, out long
previousCount)
{
ReleaseSemaphoreNative(Handle, releaseCount, out
previousCount);
}

public void ReleaseSemaphore(long releaseCount)
{
long previousCount;
ReleaseSemaphoreNative(Handle, releaseCount, out
previousCount);
}

public void ReleaseSemaphore()
{
long previousCount;
ReleaseSemaphoreNative(Handle, 1, out previousCount);
}

[MethodImplAttribute(MethodImplOptions.InternalCall )]
extern private static IntPtr CreateSemaphoreNative(long
initialCount, long maximumCount, String name, out bool createdNew);

[MethodImplAttribute(MethodImplOptions.InternalCall )]
extern private static void ReleaseSemaphoreNative(IntPtr handle,
long releaseCount, out long previousCount);

}
}
--
Reginald Blue
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my
telephone."
- Bjarne Stroustrup (originator of C++) [quoted at the 2003
International Conference on Intelligent User Interfaces]
Nov 17 '05 #18
I did a managed semaphore in c# and has been on the CodeProject for some
time:
http://www.codeproject.com/csharp/Di...gSemaphore.asp
You should be able to modify for your needs.

--
William Stacey [MVP]

"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
I have a C# application and a VB6 application that need to share a dialup
connection to the internet. Don't ask why, this is one of those corporate
"do
or die" things.

The only way I can see to do this is by using the combination of a MUTEX
to
create a Cross-application Singleton for the Dialing operation and a Named
Semphore that can keep a count of how many processes are currently sharing
the connection from the client's workstation into our corporate VPN
extranet.
I am trying to find an example of how to manage semaphores in C# in a
class.
I will have to translate the same into the VB6 for the legacy app.

Using .NET 2.0 is not an option, they won't let me use a BETA. Neither is
remoting. I have to make the access sharable between executables modules.
Does any one have any ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

Nov 17 '05 #19
I did a managed semaphore in c# and has been on the CodeProject for some
time:
http://www.codeproject.com/csharp/Di...gSemaphore.asp
You should be able to modify for your needs.

--
William Stacey [MVP]

"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
I have a C# application and a VB6 application that need to share a dialup
connection to the internet. Don't ask why, this is one of those corporate
"do
or die" things.

The only way I can see to do this is by using the combination of a MUTEX
to
create a Cross-application Singleton for the Dialing operation and a Named
Semphore that can keep a count of how many processes are currently sharing
the connection from the client's workstation into our corporate VPN
extranet.
I am trying to find an example of how to manage semaphores in C# in a
class.
I will have to translate the same into the VB6 for the legacy app.

Using .NET 2.0 is not an option, they won't let me use a BETA. Neither is
remoting. I have to make the access sharable between executables modules.
Does any one have any ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

Nov 17 '05 #20
Dear Mr. Stacey,
as you seem not to figure out, Kenneth needs a semaphore which would be
shared among two processes. Your semaphore implementation published on
CodeProject is not a choice for him (not to forget the deadlock problem you
have with it)

"William Stacey [MVP]" <st*****@mvps.org> wrote in message
news:u2**************@TK2MSFTNGP10.phx.gbl...
I did a managed semaphore in c# and has been on the CodeProject for some
time:
http://www.codeproject.com/csharp/Di...gSemaphore.asp
You should be able to modify for your needs.

--
William Stacey [MVP]

"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
I have a C# application and a VB6 application that need to share a dialup
connection to the internet. Don't ask why, this is one of those corporate "do
or die" things.

The only way I can see to do this is by using the combination of a MUTEX
to
create a Cross-application Singleton for the Dialing operation and a Named Semphore that can keep a count of how many processes are currently sharing the connection from the client's workstation into our corporate VPN
extranet.
I am trying to find an example of how to manage semaphores in C# in a
class.
I will have to translate the same into the VB6 for the legacy app.

Using .NET 2.0 is not an option, they won't let me use a BETA. Neither is remoting. I have to make the access sharable between executables modules. Does any one have any ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL


Nov 17 '05 #21
Dear Mr. Stacey,
as you seem not to figure out, Kenneth needs a semaphore which would be
shared among two processes. Your semaphore implementation published on
CodeProject is not a choice for him (not to forget the deadlock problem you
have with it)

"William Stacey [MVP]" <st*****@mvps.org> wrote in message
news:u2**************@TK2MSFTNGP10.phx.gbl...
I did a managed semaphore in c# and has been on the CodeProject for some
time:
http://www.codeproject.com/csharp/Di...gSemaphore.asp
You should be able to modify for your needs.

--
William Stacey [MVP]

"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
I have a C# application and a VB6 application that need to share a dialup
connection to the internet. Don't ask why, this is one of those corporate "do
or die" things.

The only way I can see to do this is by using the combination of a MUTEX
to
create a Cross-application Singleton for the Dialing operation and a Named Semphore that can keep a count of how many processes are currently sharing the connection from the client's workstation into our corporate VPN
extranet.
I am trying to find an example of how to manage semaphores in C# in a
class.
I will have to translate the same into the VB6 for the legacy app.

Using .NET 2.0 is not an option, they won't let me use a BETA. Neither is remoting. I have to make the access sharable between executables modules. Does any one have any ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL


Nov 17 '05 #22
William;
Thanks for your advice and the code but this still does not solve the
problem. The two applications are two separate executables that run
simultaneously and need to share resources. Actually there are three;
however, the customers I have to get this working for use only two of them.
The Monitor class only works within a single application. It can only limit
access to objects created by that executable and its underlying threads. A
seperate executable does not have access to the same instance of the Monitor
class that was created by the first stand alone application.

What I need is a method to synchronize access to the RAS system where
one stand-alone application does not interfere with the access to the RAS,
DUNS, and Internet of another stand-alone application: given that I control
the source code for both. We do not have the luxury at this time of
completely re-writing the VB6 app in C# or even porting it to VB.NET. I am
the only one working on the connectivity part of these two applications and I
also have to handle the hand-written EDI translaters for the project. I have
until the end of September to accomplish this.

I know, you probably get projects like this thrown in your face every
day. Let me just put the overview out for you for just a minute.

1.) We have 2 separate stand-alone applications we use to transmit data over
the Internet via a IPSec VPN.

2.) The newest of these is written almost completely in C#.NET and only uses
1 ActiveX component: a Dialer from Catalyst. This application will eventually
take over all of our connectivity needs except for faxing.

3.) The older stand-alone application is written in VB6 and uses the old
Cresent Internet Controls. We still conduct our primary transfers via this
app (where the $$$'s go).

4.) They want me to create a means by which if one of these dials into the
VPN first and then the second needs access as well to have the second skip
the dialer routine (that part I've got figured out) and go ahead and log into
the remote host.

5.) Now comes the tricky part, if the first app finishes its transfer before
the second one, it cannot hangup the connection. And visa versa. Only when no
one else is connected can the IPSec tunnel be dropped.

See the dilema?
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"William Stacey [MVP]" wrote:
I did a managed semaphore in c# and has been on the CodeProject for some
time:
http://www.codeproject.com/csharp/Di...gSemaphore.asp
You should be able to modify for your needs.

--
William Stacey [MVP]

"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
I have a C# application and a VB6 application that need to share a dialup
connection to the internet. Don't ask why, this is one of those corporate
"do
or die" things.

The only way I can see to do this is by using the combination of a MUTEX
to
create a Cross-application Singleton for the Dialing operation and a Named
Semphore that can keep a count of how many processes are currently sharing
the connection from the client's workstation into our corporate VPN
extranet.
I am trying to find an example of how to manage semaphores in C# in a
class.
I will have to translate the same into the VB6 for the legacy app.

Using .NET 2.0 is not an option, they won't let me use a BETA. Neither is
remoting. I have to make the access sharable between executables modules.
Does any one have any ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL


Nov 17 '05 #23
William;
Thanks for your advice and the code but this still does not solve the
problem. The two applications are two separate executables that run
simultaneously and need to share resources. Actually there are three;
however, the customers I have to get this working for use only two of them.
The Monitor class only works within a single application. It can only limit
access to objects created by that executable and its underlying threads. A
seperate executable does not have access to the same instance of the Monitor
class that was created by the first stand alone application.

What I need is a method to synchronize access to the RAS system where
one stand-alone application does not interfere with the access to the RAS,
DUNS, and Internet of another stand-alone application: given that I control
the source code for both. We do not have the luxury at this time of
completely re-writing the VB6 app in C# or even porting it to VB.NET. I am
the only one working on the connectivity part of these two applications and I
also have to handle the hand-written EDI translaters for the project. I have
until the end of September to accomplish this.

I know, you probably get projects like this thrown in your face every
day. Let me just put the overview out for you for just a minute.

1.) We have 2 separate stand-alone applications we use to transmit data over
the Internet via a IPSec VPN.

2.) The newest of these is written almost completely in C#.NET and only uses
1 ActiveX component: a Dialer from Catalyst. This application will eventually
take over all of our connectivity needs except for faxing.

3.) The older stand-alone application is written in VB6 and uses the old
Cresent Internet Controls. We still conduct our primary transfers via this
app (where the $$$'s go).

4.) They want me to create a means by which if one of these dials into the
VPN first and then the second needs access as well to have the second skip
the dialer routine (that part I've got figured out) and go ahead and log into
the remote host.

5.) Now comes the tricky part, if the first app finishes its transfer before
the second one, it cannot hangup the connection. And visa versa. Only when no
one else is connected can the IPSec tunnel be dropped.

See the dilema?
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"William Stacey [MVP]" wrote:
I did a managed semaphore in c# and has been on the CodeProject for some
time:
http://www.codeproject.com/csharp/Di...gSemaphore.asp
You should be able to modify for your needs.

--
William Stacey [MVP]

"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
I have a C# application and a VB6 application that need to share a dialup
connection to the internet. Don't ask why, this is one of those corporate
"do
or die" things.

The only way I can see to do this is by using the combination of a MUTEX
to
create a Cross-application Singleton for the Dialing operation and a Named
Semphore that can keep a count of how many processes are currently sharing
the connection from the client's workstation into our corporate VPN
extranet.
I am trying to find an example of how to manage semaphores in C# in a
class.
I will have to translate the same into the VB6 for the legacy app.

Using .NET 2.0 is not an option, they won't let me use a BETA. Neither is
remoting. I have to make the access sharable between executables modules.
Does any one have any ideas.
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL


Nov 17 '05 #24
mag
then why don't you check the VPN connectivity prior to dialing?
http://msdn.microsoft.com/library/de...nectstatus.asp
"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
William;
Thanks for your advice and the code but this still does not solve the
problem. The two applications are two separate executables that run
simultaneously and need to share resources. Actually there are three;
however, the customers I have to get this working for use only two of
them.
The Monitor class only works within a single application. It can only
limit
access to objects created by that executable and its underlying threads. A
seperate executable does not have access to the same instance of the
Monitor
class that was created by the first stand alone application.

What I need is a method to synchronize access to the RAS system where
one stand-alone application does not interfere with the access to the RAS,
DUNS, and Internet of another stand-alone application: given that I
control
the source code for both. We do not have the luxury at this time of
completely re-writing the VB6 app in C# or even porting it to VB.NET. I am
the only one working on the connectivity part of these two applications
and I
also have to handle the hand-written EDI translaters for the project. I
have
until the end of September to accomplish this.

I know, you probably get projects like this thrown in your face every
day. Let me just put the overview out for you for just a minute.

1.) We have 2 separate stand-alone applications we use to transmit data
over
the Internet via a IPSec VPN.

2.) The newest of these is written almost completely in C#.NET and only
uses
1 ActiveX component: a Dialer from Catalyst. This application will
eventually
take over all of our connectivity needs except for faxing.

3.) The older stand-alone application is written in VB6 and uses the old
Cresent Internet Controls. We still conduct our primary transfers via this
app (where the $$$'s go).

4.) They want me to create a means by which if one of these dials into the
VPN first and then the second needs access as well to have the second skip
the dialer routine (that part I've got figured out) and go ahead and log
into
the remote host.

5.) Now comes the tricky part, if the first app finishes its transfer
before
the second one, it cannot hangup the connection. And visa versa. Only when
no
one else is connected can the IPSec tunnel be dropped.

See the dilema?
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"William Stacey [MVP]" wrote:
I did a managed semaphore in c# and has been on the CodeProject for some
time:
http://www.codeproject.com/csharp/Di...gSemaphore.asp
You should be able to modify for your needs.

--
William Stacey [MVP]

"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
>I have a C# application and a VB6 application that need to share a
>dialup
> connection to the internet. Don't ask why, this is one of those
> corporate
> "do
> or die" things.
>
> The only way I can see to do this is by using the combination of a
> MUTEX
> to
> create a Cross-application Singleton for the Dialing operation and a
> Named
> Semphore that can keep a count of how many processes are currently
> sharing
> the connection from the client's workstation into our corporate VPN
> extranet.
> I am trying to find an example of how to manage semaphores in C# in a
> class.
> I will have to translate the same into the VB6 for the legacy app.
>
> Using .NET 2.0 is not an option, they won't let me use a BETA. Neither
> is
> remoting. I have to make the access sharable between executables
> modules.
> Does any one have any ideas.
> --
> Kenneth A. Jinks, Jr.
> Lead Project Software Engineer
> LabCorp CPG - LCM Development
> Huntsville, AL
>


Nov 17 '05 #25
mag
then why don't you check the VPN connectivity prior to dialing?
http://msdn.microsoft.com/library/de...nectstatus.asp
"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
William;
Thanks for your advice and the code but this still does not solve the
problem. The two applications are two separate executables that run
simultaneously and need to share resources. Actually there are three;
however, the customers I have to get this working for use only two of
them.
The Monitor class only works within a single application. It can only
limit
access to objects created by that executable and its underlying threads. A
seperate executable does not have access to the same instance of the
Monitor
class that was created by the first stand alone application.

What I need is a method to synchronize access to the RAS system where
one stand-alone application does not interfere with the access to the RAS,
DUNS, and Internet of another stand-alone application: given that I
control
the source code for both. We do not have the luxury at this time of
completely re-writing the VB6 app in C# or even porting it to VB.NET. I am
the only one working on the connectivity part of these two applications
and I
also have to handle the hand-written EDI translaters for the project. I
have
until the end of September to accomplish this.

I know, you probably get projects like this thrown in your face every
day. Let me just put the overview out for you for just a minute.

1.) We have 2 separate stand-alone applications we use to transmit data
over
the Internet via a IPSec VPN.

2.) The newest of these is written almost completely in C#.NET and only
uses
1 ActiveX component: a Dialer from Catalyst. This application will
eventually
take over all of our connectivity needs except for faxing.

3.) The older stand-alone application is written in VB6 and uses the old
Cresent Internet Controls. We still conduct our primary transfers via this
app (where the $$$'s go).

4.) They want me to create a means by which if one of these dials into the
VPN first and then the second needs access as well to have the second skip
the dialer routine (that part I've got figured out) and go ahead and log
into
the remote host.

5.) Now comes the tricky part, if the first app finishes its transfer
before
the second one, it cannot hangup the connection. And visa versa. Only when
no
one else is connected can the IPSec tunnel be dropped.

See the dilema?
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"William Stacey [MVP]" wrote:
I did a managed semaphore in c# and has been on the CodeProject for some
time:
http://www.codeproject.com/csharp/Di...gSemaphore.asp
You should be able to modify for your needs.

--
William Stacey [MVP]

"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
>I have a C# application and a VB6 application that need to share a
>dialup
> connection to the internet. Don't ask why, this is one of those
> corporate
> "do
> or die" things.
>
> The only way I can see to do this is by using the combination of a
> MUTEX
> to
> create a Cross-application Singleton for the Dialing operation and a
> Named
> Semphore that can keep a count of how many processes are currently
> sharing
> the connection from the client's workstation into our corporate VPN
> extranet.
> I am trying to find an example of how to manage semaphores in C# in a
> class.
> I will have to translate the same into the VB6 for the legacy app.
>
> Using .NET 2.0 is not an option, they won't let me use a BETA. Neither
> is
> remoting. I have to make the access sharable between executables
> modules.
> Does any one have any ideas.
> --
> Kenneth A. Jinks, Jr.
> Lead Project Software Engineer
> LabCorp CPG - LCM Development
> Huntsville, AL
>


Nov 17 '05 #26
As I said, he could modify it pretty easy. Instead of monitor, use a named
mutex and shared file to hold the count or mem mapped file, etc. Mind
sharing what deadlock problem there is? I would be happy to fix it. TIA.

--
William Stacey [MVP]

"Lebesgue" <no****@spam.jp> wrote in message
news:Oc*************@TK2MSFTNGP11.phx.gbl...
Dear Mr. Stacey,
as you seem not to figure out, Kenneth needs a semaphore which would be
shared among two processes. Your semaphore implementation published on
CodeProject is not a choice for him (not to forget the deadlock problem
you
have with it)

"William Stacey [MVP]" <st*****@mvps.org> wrote in message
news:u2**************@TK2MSFTNGP10.phx.gbl...
I did a managed semaphore in c# and has been on the CodeProject for some
time:
http://www.codeproject.com/csharp/Di...gSemaphore.asp
You should be able to modify for your needs.

--
William Stacey [MVP]

"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
>I have a C# application and a VB6 application that need to share a
>dialup
> connection to the internet. Don't ask why, this is one of those corporate > "do
> or die" things.
>
> The only way I can see to do this is by using the combination of a
> MUTEX
> to
> create a Cross-application Singleton for the Dialing operation and a Named > Semphore that can keep a count of how many processes are currently sharing > the connection from the client's workstation into our corporate VPN
> extranet.
> I am trying to find an example of how to manage semaphores in C# in a
> class.
> I will have to translate the same into the VB6 for the legacy app.
>
> Using .NET 2.0 is not an option, they won't let me use a BETA. Neither is > remoting. I have to make the access sharable between executables modules. > Does any one have any ideas.
> --
> Kenneth A. Jinks, Jr.
> Lead Project Software Engineer
> LabCorp CPG - LCM Development
> Huntsville, AL
>



Nov 17 '05 #27
As I said, he could modify it pretty easy. Instead of monitor, use a named
mutex and shared file to hold the count or mem mapped file, etc. Mind
sharing what deadlock problem there is? I would be happy to fix it. TIA.

--
William Stacey [MVP]

"Lebesgue" <no****@spam.jp> wrote in message
news:Oc*************@TK2MSFTNGP11.phx.gbl...
Dear Mr. Stacey,
as you seem not to figure out, Kenneth needs a semaphore which would be
shared among two processes. Your semaphore implementation published on
CodeProject is not a choice for him (not to forget the deadlock problem
you
have with it)

"William Stacey [MVP]" <st*****@mvps.org> wrote in message
news:u2**************@TK2MSFTNGP10.phx.gbl...
I did a managed semaphore in c# and has been on the CodeProject for some
time:
http://www.codeproject.com/csharp/Di...gSemaphore.asp
You should be able to modify for your needs.

--
William Stacey [MVP]

"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
>I have a C# application and a VB6 application that need to share a
>dialup
> connection to the internet. Don't ask why, this is one of those corporate > "do
> or die" things.
>
> The only way I can see to do this is by using the combination of a
> MUTEX
> to
> create a Cross-application Singleton for the Dialing operation and a Named > Semphore that can keep a count of how many processes are currently sharing > the connection from the client's workstation into our corporate VPN
> extranet.
> I am trying to find an example of how to manage semaphores in C# in a
> class.
> I will have to translate the same into the VB6 for the legacy app.
>
> Using .NET 2.0 is not an option, they won't let me use a BETA. Neither is > remoting. I have to make the access sharable between executables modules. > Does any one have any ideas.
> --
> Kenneth A. Jinks, Jr.
> Lead Project Software Engineer
> LabCorp CPG - LCM Development
> Huntsville, AL
>



Nov 17 '05 #28
Change the monitor to a named mutex and use a mem mapped file to hold the
shared counter (or plain disk file).

--
William Stacey [MVP]

"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
William;
Thanks for your advice and the code but this still does not solve the
problem. The two applications are two separate executables that run
simultaneously and need to share resources. Actually there are three;
however, the customers I have to get this working for use only two of
them.
The Monitor class only works within a single application. It can only
limit
access to objects created by that executable and its underlying threads. A
seperate executable does not have access to the same instance of the
Monitor
class that was created by the first stand alone application.

What I need is a method to synchronize access to the RAS system where
one stand-alone application does not interfere with the access to the RAS,
DUNS, and Internet of another stand-alone application: given that I
control
the source code for both. We do not have the luxury at this time of
completely re-writing the VB6 app in C# or even porting it to VB.NET. I am
the only one working on the connectivity part of these two applications
and I
also have to handle the hand-written EDI translaters for the project. I
have
until the end of September to accomplish this.

I know, you probably get projects like this thrown in your face every
day. Let me just put the overview out for you for just a minute.

1.) We have 2 separate stand-alone applications we use to transmit data
over
the Internet via a IPSec VPN.

2.) The newest of these is written almost completely in C#.NET and only
uses
1 ActiveX component: a Dialer from Catalyst. This application will
eventually
take over all of our connectivity needs except for faxing.

3.) The older stand-alone application is written in VB6 and uses the old
Cresent Internet Controls. We still conduct our primary transfers via this
app (where the $$$'s go).

4.) They want me to create a means by which if one of these dials into the
VPN first and then the second needs access as well to have the second skip
the dialer routine (that part I've got figured out) and go ahead and log
into
the remote host.

5.) Now comes the tricky part, if the first app finishes its transfer
before
the second one, it cannot hangup the connection. And visa versa. Only when
no
one else is connected can the IPSec tunnel be dropped.

See the dilema?
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"William Stacey [MVP]" wrote:
I did a managed semaphore in c# and has been on the CodeProject for some
time:
http://www.codeproject.com/csharp/Di...gSemaphore.asp
You should be able to modify for your needs.

--
William Stacey [MVP]

"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
>I have a C# application and a VB6 application that need to share a
>dialup
> connection to the internet. Don't ask why, this is one of those
> corporate
> "do
> or die" things.
>
> The only way I can see to do this is by using the combination of a
> MUTEX
> to
> create a Cross-application Singleton for the Dialing operation and a
> Named
> Semphore that can keep a count of how many processes are currently
> sharing
> the connection from the client's workstation into our corporate VPN
> extranet.
> I am trying to find an example of how to manage semaphores in C# in a
> class.
> I will have to translate the same into the VB6 for the legacy app.
>
> Using .NET 2.0 is not an option, they won't let me use a BETA. Neither
> is
> remoting. I have to make the access sharable between executables
> modules.
> Does any one have any ideas.
> --
> Kenneth A. Jinks, Jr.
> Lead Project Software Engineer
> LabCorp CPG - LCM Development
> Huntsville, AL
>


Nov 17 '05 #29
Change the monitor to a named mutex and use a mem mapped file to hold the
shared counter (or plain disk file).

--
William Stacey [MVP]

"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
William;
Thanks for your advice and the code but this still does not solve the
problem. The two applications are two separate executables that run
simultaneously and need to share resources. Actually there are three;
however, the customers I have to get this working for use only two of
them.
The Monitor class only works within a single application. It can only
limit
access to objects created by that executable and its underlying threads. A
seperate executable does not have access to the same instance of the
Monitor
class that was created by the first stand alone application.

What I need is a method to synchronize access to the RAS system where
one stand-alone application does not interfere with the access to the RAS,
DUNS, and Internet of another stand-alone application: given that I
control
the source code for both. We do not have the luxury at this time of
completely re-writing the VB6 app in C# or even porting it to VB.NET. I am
the only one working on the connectivity part of these two applications
and I
also have to handle the hand-written EDI translaters for the project. I
have
until the end of September to accomplish this.

I know, you probably get projects like this thrown in your face every
day. Let me just put the overview out for you for just a minute.

1.) We have 2 separate stand-alone applications we use to transmit data
over
the Internet via a IPSec VPN.

2.) The newest of these is written almost completely in C#.NET and only
uses
1 ActiveX component: a Dialer from Catalyst. This application will
eventually
take over all of our connectivity needs except for faxing.

3.) The older stand-alone application is written in VB6 and uses the old
Cresent Internet Controls. We still conduct our primary transfers via this
app (where the $$$'s go).

4.) They want me to create a means by which if one of these dials into the
VPN first and then the second needs access as well to have the second skip
the dialer routine (that part I've got figured out) and go ahead and log
into
the remote host.

5.) Now comes the tricky part, if the first app finishes its transfer
before
the second one, it cannot hangup the connection. And visa versa. Only when
no
one else is connected can the IPSec tunnel be dropped.

See the dilema?
--
Kenneth A. Jinks, Jr.
Lead Project Software Engineer
LabCorp CPG - LCM Development
Huntsville, AL

"William Stacey [MVP]" wrote:
I did a managed semaphore in c# and has been on the CodeProject for some
time:
http://www.codeproject.com/csharp/Di...gSemaphore.asp
You should be able to modify for your needs.

--
William Stacey [MVP]

"jinksk" <ji****@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
>I have a C# application and a VB6 application that need to share a
>dialup
> connection to the internet. Don't ask why, this is one of those
> corporate
> "do
> or die" things.
>
> The only way I can see to do this is by using the combination of a
> MUTEX
> to
> create a Cross-application Singleton for the Dialing operation and a
> Named
> Semphore that can keep a count of how many processes are currently
> sharing
> the connection from the client's workstation into our corporate VPN
> extranet.
> I am trying to find an example of how to manage semaphores in C# in a
> class.
> I will have to translate the same into the VB6 for the legacy app.
>
> Using .NET 2.0 is not an option, they won't let me use a BETA. Neither
> is
> remoting. I have to make the access sharable between executables
> modules.
> Does any one have any ideas.
> --
> Kenneth A. Jinks, Jr.
> Lead Project Software Engineer
> LabCorp CPG - LCM Development
> Huntsville, AL
>


Nov 17 '05 #30

"William Stacey [MVP]" <st*****@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
As I said, he could modify it pretty easy. Instead of monitor, use a named mutex and shared file to hold the count or mem mapped file, etc. Mind
sharing what deadlock problem there is? I would be happy to fix it. TIA.

--
William Stacey [MVP]


As stated in the discussion under your article:
(http://www.codeproject.com/csharp/Di...sp#xx1185086xx
)

public bool Acquire(int millisecondsTimeout)
{
lock(syncLock)
{
...snip...
Monitor.Wait(syncLock, millisecondsTimeout)
...snip...
}
}
public void Release(int releaseCount)
{
...snip...
lock(syncLock)
{
...snip...
Monitor.PulseAll(syncLock);
...snip...
}
}

To aquire a lock on the semaphore, you need to obtain syncLock (which is
released the moment you leave the function). If there are no slots
available, you block at the Monitor.Wait() call, INSIDE the lock statement.
When a different thread finishes up and tries to release, it attempts to
aquire the exclusive lock on syncLock. Since there is a thread blocking on
Monitor.Wait() inside the lock, this won't release.

Nov 17 '05 #31

"William Stacey [MVP]" <st*****@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
As I said, he could modify it pretty easy. Instead of monitor, use a named mutex and shared file to hold the count or mem mapped file, etc. Mind
sharing what deadlock problem there is? I would be happy to fix it. TIA.

--
William Stacey [MVP]


As stated in the discussion under your article:
(http://www.codeproject.com/csharp/Di...sp#xx1185086xx
)

public bool Acquire(int millisecondsTimeout)
{
lock(syncLock)
{
...snip...
Monitor.Wait(syncLock, millisecondsTimeout)
...snip...
}
}
public void Release(int releaseCount)
{
...snip...
lock(syncLock)
{
...snip...
Monitor.PulseAll(syncLock);
...snip...
}
}

To aquire a lock on the semaphore, you need to obtain syncLock (which is
released the moment you leave the function). If there are no slots
available, you block at the Monitor.Wait() call, INSIDE the lock statement.
When a different thread finishes up and tries to release, it attempts to
aquire the exclusive lock on syncLock. Since there is a thread blocking on
Monitor.Wait() inside the lock, this won't release.

Nov 17 '05 #32
Monitor.Wait releases the lock.

"Lebesgue" <no****@spam.jp> wrote in message
news:u4**************@TK2MSFTNGP10.phx.gbl...

"William Stacey [MVP]" <st*****@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
As I said, he could modify it pretty easy. Instead of monitor, use a

named
mutex and shared file to hold the count or mem mapped file, etc. Mind
sharing what deadlock problem there is? I would be happy to fix it.
TIA.

--
William Stacey [MVP]


As stated in the discussion under your article:
(http://www.codeproject.com/csharp/Di...sp#xx1185086xx
)

public bool Acquire(int millisecondsTimeout)
{
lock(syncLock)
{
...snip...
Monitor.Wait(syncLock, millisecondsTimeout)
...snip...
}
}
public void Release(int releaseCount)
{
...snip...
lock(syncLock)
{
...snip...
Monitor.PulseAll(syncLock);
...snip...
}
}

To aquire a lock on the semaphore, you need to obtain syncLock (which is
released the moment you leave the function). If there are no slots
available, you block at the Monitor.Wait() call, INSIDE the lock
statement.
When a different thread finishes up and tries to release, it attempts to
aquire the exclusive lock on syncLock. Since there is a thread blocking on
Monitor.Wait() inside the lock, this won't release.

Nov 17 '05 #33
Monitor.Wait releases the lock.

"Lebesgue" <no****@spam.jp> wrote in message
news:u4**************@TK2MSFTNGP10.phx.gbl...

"William Stacey [MVP]" <st*****@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
As I said, he could modify it pretty easy. Instead of monitor, use a

named
mutex and shared file to hold the count or mem mapped file, etc. Mind
sharing what deadlock problem there is? I would be happy to fix it.
TIA.

--
William Stacey [MVP]


As stated in the discussion under your article:
(http://www.codeproject.com/csharp/Di...sp#xx1185086xx
)

public bool Acquire(int millisecondsTimeout)
{
lock(syncLock)
{
...snip...
Monitor.Wait(syncLock, millisecondsTimeout)
...snip...
}
}
public void Release(int releaseCount)
{
...snip...
lock(syncLock)
{
...snip...
Monitor.PulseAll(syncLock);
...snip...
}
}

To aquire a lock on the semaphore, you need to obtain syncLock (which is
released the moment you leave the function). If there are no slots
available, you block at the Monitor.Wait() call, INSIDE the lock
statement.
When a different thread finishes up and tries to release, it attempts to
aquire the exclusive lock on syncLock. Since there is a thread blocking on
Monitor.Wait() inside the lock, this won't release.

Nov 17 '05 #34
As Nigel correctly points out, the implementation is correct and a well
known pattern in this type of producer-consumer locking patterns.
Monitor.Wait releases the lock so a thread calling Release is not blocked.
The lock will be reacquired for the Acquire thread *before Monitor.Wait
returns (unless there is a timeout or some mutex exception) - so the rest of
the code is still "inside" the lock. The monitor queue itself will
determine which thread gets the lock after a Pulse operation - but only one
thread will receive the lock and be able to continue on. So the pattern is
sound and well-known.

--
William Stacey [MVP]

"Lebesgue" <no****@spam.jp> wrote in message
news:u4**************@TK2MSFTNGP10.phx.gbl...

"William Stacey [MVP]" <st*****@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
As I said, he could modify it pretty easy. Instead of monitor, use a

named
mutex and shared file to hold the count or mem mapped file, etc. Mind
sharing what deadlock problem there is? I would be happy to fix it.
TIA.

--
William Stacey [MVP]


As stated in the discussion under your article:
(http://www.codeproject.com/csharp/Di...sp#xx1185086xx
)

public bool Acquire(int millisecondsTimeout)
{
lock(syncLock)
{
...snip...
Monitor.Wait(syncLock, millisecondsTimeout)
...snip...
}
}
public void Release(int releaseCount)
{
...snip...
lock(syncLock)
{
...snip...
Monitor.PulseAll(syncLock);
...snip...
}
}

To aquire a lock on the semaphore, you need to obtain syncLock (which is
released the moment you leave the function). If there are no slots
available, you block at the Monitor.Wait() call, INSIDE the lock
statement.
When a different thread finishes up and tries to release, it attempts to
aquire the exclusive lock on syncLock. Since there is a thread blocking on
Monitor.Wait() inside the lock, this won't release.

Nov 17 '05 #35

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nish | last post by:
Hi, I have some code, to which I added usage of posix semaphores. I am working on a solaris platform. After doing that, my process becomes unkillable, that is it will not terminate if sent a...
1
by: Mehmet Turker | last post by:
Hi; In a research project, I want to use shared memory with semaphores. First I have to create an environment for interprocess messaging. I'm thinking of having a main process which creates a big...
2
by: schneider jp | last post by:
Hi everybody For a project of system programming, we need to use semaphores, but i got some pbs... when I compile, i get perror with sem_open("machin", O_CREAT, 0666, 0); and perror says...
11
by: FiLH | last post by:
Hello, I would like to know if posix semaphores are inter processes or just semaphores for threads inside the same process. I have not seen it defined in the posix specification I have found,...
1
by: jinksk | last post by:
I have a C# application and a VB6 application that need to share a dialup connection to the internet. Don't ask why, this is one of those corporate "do or die" things. The only way I can see to...
1
by: Edwin New | last post by:
I have a requirement to run two separate postmasters on the one machine. It looks like they compete for resources (semaphores) so won't run concurrently. I compiled twice, specifying different...
5
by: Steven Spencer | last post by:
Hi, I'm doing an IT degree at university, and my lecturer's do not teach m$ technologies. I was wondering if anyone could point me to the implementation of mutex's and semaphores in .net? Or the...
0
arne
by: arne | last post by:
Hi, I am using Perl ithreads. The threads I create shall access a shared hash. In order to control access to the hash, I would like to use a semaphore. (BTW, does the hash need the protection at...
0
by: The Advocate | last post by:
Hello, how can we implement semaphores using monitors. I got how we can do it the way round. I did alot of search but couldnt find any implementation of semaphores using monitors,. Can anyone help me...
5
by: davidcollins001 | last post by:
Hi, Firstly please excuse the long ramblingness. I need some conceptual help, I am trying to make two programs that are exactly the same but take it in turns to execute something, so the output...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.