Hello NG,
is there a possibillity to determine how long a thread had to wait on
Monitor.TryEnte r(lockObj,timeo ut) ?
Thanks for hints.
Rainer Queck 5 3816
On Nov 6, 12:40 pm, "Rainer Queck" <Rai...@noemail .noemailwrote:
is there a possibillity to determine how long a thread had to wait on
Monitor.TryEnte r(lockObj,timeo ut) ?
Only by timing it - e.g. using the Stopwatch class.
Jon
Rainer Queck wrote:
Hello NG,
is there a possibillity to determine how long a thread had to wait on
Monitor.TryEnte r(lockObj,timeo ut) ?
You could take a snapshot of DateTime.Now both before and after it
acquires the lock, subtract them and interrogate the resulting TimeSpan:
DateTime startAcquire = DateTime.Now;
Monitor.TryEnte r(lockObj,timeo ut);
DateTime endAcquire = DateTime.Now;
TimeSpan waitTime = endAcquire - startAcquire;
Chris.
Hi Jon, Hi Chris,
but would it be impossible to determine who does the StopWatch.Reset/Start
(or DateTime.Now) and who reads it?
Excample
StopWatch.Reset ();
StopWatch.Start ();
if(Monitor.TryE nter(lockObj,ti meout) )
{
long ticks = StopWatch.Elaps edTicks();
DoTimeConsuming AccessToResourc e();
}
lets assume
thread1 comes. No Problem
while thread 1 is still working inside thread two come and has to wait.
Still no problem
BUT now it thread3 comes allong thread 1 is STILL working, it will do a
reset of the StopWatch before it starts waiting, won't it?
Now if thread2 can enter, ticks will have a wrong value true?
Regards
Rainer
On Nov 6, 1:54 pm, "Rainer Queck" <Rai...@noemail .noemailwrote:
but would it be impossible to determine who does the StopWatch.Reset/Start
(or DateTime.Now) and who reads it?
You'd create a separate Stopwatch for that particular call - only that
thread would even know about it.
Jon
Thanks for that hint.
I wasn't sure that local vars are "on the stack".
Regards
Rainer
"Jon Skeet [C# MVP]" <sk***@pobox.co mschrieb im Newsbeitrag
news:11******** **************@ 50g2000hsm.goog legroups.com...
On Nov 6, 1:54 pm, "Rainer Queck" <Rai...@noemail .noemailwrote:
>but would it be impossible to determine who does the StopWatch.Rese t/Start (or DateTime.Now) and who reads it?
You'd create a separate Stopwatch for that particular call - only that
thread would even know about it.
Jon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Brett Robichaud |
last post by:
I need to make access to a reference object threadsafe. My natural instinct
was to simply use Monitor.Enter() and Exit(). The problem is that the
object behind the reference changes frequently, so my understanding of
Monitor indicates this would not protect my object. Example:
Bitmap bmp = new Bitmap("x.jpg");
Monitor.Enter(bmp);
bmp =...
|
by: slowram |
last post by:
I know how to get the monitor dimensions, virtual monitor dimensions,
but how do I get the location of the second monitor in relationship to
the original?
On the desktop when I go into my property settings for the monitor I
can move around the monitors so if say the second monitor is lower
than the first I can position it accordingly. Are...
|
by: Charles Law |
last post by:
I've been using monitors a bit lately (some of you may have heard ;-) ) and
then up pop Manual and AutoResetEvents , and they look for all the world
like the same thing.
Are they interchangeable, or when should I use one over the other?
TIA
Charles
|
by: Michael Kennedy |
last post by:
Hi,
I have been looking into the claim that the keyword lock is not safe
when exceptions are possible. That lead me to try the following code,
which I think has uncovered a serious error in the .NET 2.0 framework.
Note that this runs better, but not perfectly, on .NET 1.1.
Note: The numbers are line numbers needed to match the callstack...
|
by: fournij |
last post by:
Hi
I'm writing a MFC C++ application using Visual .NET. I'm using a Dual
Head video card with 2 monitors. I want to start my application in the
first monitor but open a dialog box in the second monitor. I tried to
set the X position of the dialog box greather thant the first screen
resolution, but the dialog box still appear on the first...
| |
by: www.brook |
last post by:
I have a VC++.net code. Two threads are created, one thread keeps
appending elements to the queue, another keeps deleting an element from
the queue.
I tried to use monitor, but it seems that the there is problem. in the
thread of the deleting, seems that the deleting function entered twice
and both
try to delete the queue. The first thread...
|
by: Perecli Manole |
last post by:
I am having some strange thread synchronization problems that require me to
better understand the intricacies of Monitor.Wait/Pulse.
I have 3 threads. Thread 1 does a Monitor.Wait in a SyncLock block
protecting a resource. Thread 2 and 3 also have a SyncLock block protecting
the same resource and after executing some code in their blocks...
|
by: Raj |
last post by:
Can we create an event monitor for statements in a partitioned
environment?
CREATE EVENT MONITOR stmt_event FOR STATEMENTS WRITE TO FILE
'/home/rajm/event' ON PARTITION 0 GLOBAL
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
|
by: jbenner |
last post by:
I have opened a PMR for this with IBM, and am not asking for advice from the DB2 DBA community. I am posting this as an FYI that DB2 Health Monitor, even at the latest version of DB2, still can cause huge problems with slow connect times and heavy resource locking in high concurrency / high transaction volume environments. I have an OLTP with...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |