473,320 Members | 1,612 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,320 software developers and data experts.

.Net equivalent of CRITICAL_SECTION

Hello,

can anyone tell me what the .Net equivalent of CRITICAL_SECTION is, c.q. how
I can get EnterCriticalSection etc to work without __gc conversion errors ?

TIA,

Michiel.
Nov 17 '05 #1
5 2866
Michiel wrote:
can anyone tell me what the .Net equivalent of CRITICAL_SECTION is,


Use System.Threading.Mutex.

--
Patrick Philippot - Microsoft MVP [.Net]
MainSoft Consulting Services
www.mainsoft.fr
Nov 17 '05 #2

"Patrick Philippot" <pa***************@mainsoft.xx> wrote in message
news:OB*************@tk2msftngp13.phx.gbl...
Michiel wrote:
can anyone tell me what the .Net equivalent of CRITICAL_SECTION is,


Use System.Threading.Mutex.

--
Patrick Philippot - Microsoft MVP [.Net]
MainSoft Consulting Services
www.mainsoft.fr


Works lovely, thank you !
Nov 17 '05 #3
Patrick Philippot wrote:
Michiel wrote:
can anyone tell me what the .Net equivalent of CRITICAL_SECTION is,


Use System.Threading.Mutex.


The correcter equivalent is Monitor.Enter/Exit

or in C# the "lock" keyword, which results in:

<code>
object obj1;
Monitor.Enter(obj1 = lockObject);
try
{
// do some snychronized stuff
}
finally
{
Monitor.Exit(obj1);
}
</code>
--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server ?
http://sourceforge.net/projects/srvreport/
Nov 17 '05 #4
Jochen Kalmbach wrote:
Patrick Philippot wrote:
Michiel wrote:
can anyone tell me what the .Net equivalent of CRITICAL_SECTION is,


Use System.Threading.Mutex.


The correcter equivalent is Monitor.Enter/Exit


by the way: The difference is performance!

Mutex can be used across processes (CriticalSections not, neither Monitor).

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server ?
http://sourceforge.net/projects/srvreport/
Nov 17 '05 #5
Yeah, but I needed a worker thread to finish some section while terminating
it from it's parent process so I think in my case it was the right solution
:)

"Nadav" <Na***@discussions.microsoft.com> wrote in message
news:EF**********************************@microsof t.com...
As Jochen suggested you should rather use lock then Mutex, Mutext can cross process boundaries while lock/Monitor can't, the advantage of using a
mutex across processes doesn't come for free: any wait call being executed
on a mutex will cause the context to switch to the kernel ( even if the
state of the mutex is signaled ), CRITICAL_SECTION/lock/monitor 'cannot not'
cross process boundaries and as such will not result a context switch ( when
the object is at signaled state ) so it will not switch to the kernel. Usage of Mutex should be done just where lock/monitor cannot be used, using Mutex increases the amount context switches and this may harm
performance...
Nadav
http://www.ddevel.com

"Michiel" wrote:

"Patrick Philippot" <pa***************@mainsoft.xx> wrote in message
news:OB*************@tk2msftngp13.phx.gbl...
Michiel wrote:
> can anyone tell me what the .Net equivalent of CRITICAL_SECTION is,

Use System.Threading.Mutex.

--
Patrick Philippot - Microsoft MVP [.Net]
MainSoft Consulting Services
www.mainsoft.fr


Works lovely, thank you !

Nov 17 '05 #6

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

Similar topics

14
by: John | last post by:
Is there an equivalent of COM on Linux that I can get through Python. My need is to have some sort of language independent component framework. I can think of CORBA but I have to have a server...
2
by: Michael Foord | last post by:
Please pardon my ignorance on this one - but I'm not certain how the sign bt is treated in python bitwise operators. I've trying to convert a javascript DES encryption routine into python. ...
3
by: Robert Dodier | last post by:
Hello, Here's a thought that I'm sure has already occurred to someone else, I just can't find any record of it yet. An XML document is just a more verbose and clumsy representation of an...
1
by: Vannela | last post by:
Is there any equivalent control in .NET for the Power builder DataWindow control? I am explaining the Datawindow architecture to some extent. Power Builder DataWindow Control has got different...
7
by: Tim Conner | last post by:
Hi, I am an ex-delphi programmer, and I having a real hard time with the following simple code (example ): Which is the equivalent to the following code ? var chars : PChar; sBack, s :...
9
by: Nadav | last post by:
Hi, I am tring to pass messages between threads, using the good old C++ I would call the GetMessage/PostThreadMessage APIs, Now, I am using C# and i can't find any equivalenty for these calls, any...
10
by: karch | last post by:
How would this C# contruct be represented in C++/CLI? Or is it even possible? PolicyLevel level = (enumerator->Current) as PolicyLevel; Thanks, Karch
9
by: Alan Silver | last post by:
Hello, I'm converting some old VB6 code to use with ASP.NET and have come unstuck with the Asc() function. This was used in the old VB6 code to convert a character to its ASCII numeric...
14
by: grid | last post by:
Hi, I have a certain situation where a particular piece of code works on a particular compiler but fails on another proprietary compiler.It seems to have been fixed but I just want to confirm if...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.