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

How to release a thread from a Monitor blocking?

I’m writing a thread wrapper for a safe thread termination by using stop event.
Whenever the thread stop event is signaled, I want to release the thread in
case it’s blocked on Monitor.Enter() or Monitor.Wait().
Note that when I’m writing this code, I do not know on what object the
Monitor will block on.
Is there a way to release the thread from the Monitor blocking except using
Thread.Interrupt() (Any kind of wrapping is acceptable) ???

--
Thanks
Sharon G.
Nov 16 '05 #1
2 1620
Sharon,

Interrupt is the only thing that will stop the blocking. The only other
thing I could think of that would stop it would be to actually find the
object that is currently holding the lock, and release it on the thread that
is holding it. However, that doesn't guarantee that your thread will wake
up, because there might be other threads trying to lock on that same object.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sharon" <Sh****@discussions.microsoft.com> wrote in message
news:50**********************************@microsof t.com...
I'm writing a thread wrapper for a safe thread termination by using stop
event.
Whenever the thread stop event is signaled, I want to release the thread
in
case it's blocked on Monitor.Enter() or Monitor.Wait().
Note that when I'm writing this code, I do not know on what object the
Monitor will block on.
Is there a way to release the thread from the Monitor blocking except
using
Thread.Interrupt() (Any kind of wrapping is acceptable) ???

--
Thanks
Sharon G.

Nov 16 '05 #2
Why do you not want to use Interrupt in this situation - thats exactly what its there for

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

I'm writing a thread wrapper for a safe thread termination by using stop event.
Whenever the thread stop event is signaled, I want to release the thread in
case it's blocked on Monitor.Enter() or Monitor.Wait().
Note that when I'm writing this code, I do not know on what object the
Monitor will block on.
Is there a way to release the thread from the Monitor blocking except using
Thread.Interrupt() (Any kind of wrapping is acceptable) ???

--
Thanks
Sharon G.

Nov 16 '05 #3

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

Similar topics

4
by: John P. Speno | last post by:
So you have this problem, and you decide to use threads to solve it... System is Python 2.3.3 on Solaris 9. I'm using the classic Python thread model. Main thread puts stuff into a...
3
by: David Sworder | last post by:
This message was already cross-posted to C# and ADO.NET, but I forgot to post to this "general" group... sorry about that. It just occured to me after my first post that the "general" group readers...
4
by: Hagay Lupesko | last post by:
Hi, I've encountered a strange phenomena which appears to me as a bug: I have an engine that uses a System.Threading.Timer to invoke a delegate every X minutes. The code looks something...
2
by: Frank Rizzo | last post by:
I tried it on dotnet.vb, but got no answers. I'll try it here now. I have an app that listen to data on a certain resource. Data can come in on this resource any time, so I have to listen for it...
1
by: Sakharam Phapale | last post by:
Hi All, In following example, while playing file, if thread goes in WaitSleepJoin state, due to Thread.Sleep method. Now I want to suspend thread by clicking on cmdSuspend button. I have...
8
by: NG | last post by:
Hi All I am using interop blocking COM call from within a worker thread. This is a part of Windows Application. I find that if I remove the blocking COM call and instead use an infinite while...
5
by: Kieran Benton | last post by:
Hello, I'm currently in the tail end process of developing a high scalability server for my employer. Essentially it receives short socket based connections with an ASCII message, parses that...
6
by: les | last post by:
Here's a class which uses 2.0 generics to implement an inter-thread message queue in C#. Any number of threads can post and read from the queue simultaneously, and the message object can be any...
4
by: sherifffruitfly | last post by:
Hi all, I'm trying to to figure out this stuff, and I've got part of the trick in the code below, which updates a textbox with data from another thread. What I'd like to do is put a Pause button...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.