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 3821
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 = new Bitmap("y.jpg");
Monitor.Exit(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 these values wrote
to the registry? Is there some way to get them?
For instance I'd like to know if...
|
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 of the
exception below.
|
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 monitor.
Can you help me ?
| |
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 find it is not empty, and try
to delete an element, but before this thread actually delete it,...
|
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 they both do
a Monitor.Pulse to hand of the locked resource back to thread 1.
While thread 1 has...
|
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 30-90 transactions per second activity, and start of Health Monitor every 2 hours was crashing our...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |