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

Thread Priorities on async operations

I have a low priority background thread doing some async socket
communications.

The thread that kicks off the AsyncRead/AsyncWrite has its priority set to
'below normal'. But when the code enters the AsyncRead/AsyncWrite functions
I have discoved that the priority has been changed to 'normal'. I
understand that new threads in .Net do not inherit their creators priority
(which is cool) but what I can't understand is how to convince the
AyncRead/Write thread to be the priority of its creator.

The only thing I can think of is use some private class member to record the
creators priority when the class is created and then in the
AsyncRead/AsyncWrite to manually change the priority to the value in the
member - seems ugly to me.

/// <summary>
/// Sends the data asynchronously
/// </summary>
/// <param name="ar"></param>
private void SendAsync(IAsyncResult ar)
{
try
{
Thread.CurrentThread.Priority = this.originalThreadPriority;
...

Any suggestions?

Regards
Dave A
Nov 22 '05 #1
6 1970
You could pass the priority as a parameter when calling the methods
asynchronously and then setting the priority.

Gabriel Lozano-Morán
Nov 22 '05 #2
There is the 'object state' parameter that can be passed into
stream.BeginRead and stream.BeginWrite but I am already using this
parameter. I could create a new class that includes the thread priority but
it seems a pretty awkward solution.

Apparently Java's threads inherit the priority of their parent which would
seems a more sensible solution.

"Gabriel Lozano-Morán" <ga************@no-spam-thx.org> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
You could pass the priority as a parameter when calling the methods
asynchronously and then setting the priority.

Gabriel Lozano-Morán

Nov 22 '05 #3
Hi Dave,
There is the 'object state' parameter that can be passed into
stream.BeginRead and stream.BeginWrite but I am already using this
parameter. I could create a new class that includes the thread priority but
it seems a pretty awkward solution. Yes, pretty awkward but I think you may need it. Kind of EventArgs,
right? Think that you might even want to pass something else in the
future. It could be a nested class.
Apparently Java's threads inherit the priority of their parent which would
seems a more sensible solution.

It is true that a .NET thread does not inherit its parent priority.
However, I think .NET makes use of ThreadPool internally for such async
delegates. Members of a pool should be identical.

Regards,
Thi

Nov 22 '05 #4
Anyway if you set the priority to low you have absolutely no guarantee
whatsoever that the priority will not be changed by the operating system.

Gabriel Lozano-Morán
Nov 22 '05 #5
What do you mean?

I did not know that the OS could arbitrarily change the priority of threads.
If it does happen then it must happen under extraordinary circumstances like
an imminent power failure reported by the UPS or something. I have never
seen this happen.

Can you please quote some source.

Its not that I don't believe you - its just that I don't believe you. :-)

Regards
Dave A

"Gabriel Lozano-Morán" <ga************@no-spam-thx.org> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Anyway if you set the priority to low you have absolutely no guarantee
whatsoever that the priority will not be changed by the operating system.

Gabriel Lozano-Morán

Dec 4 '05 #6
Hi Dave,

Is it really necessary to set the thread priority to below normal?
If yes, I think it would be better you create your own thread and set
its priority instead of changing a pooling thread's priority.
See
http://msdn.microsoft.com/library/en...eadPooling.asp.

Thi

Dec 5 '05 #7

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

Similar topics

31
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not...
2
by: Bob Rock | last post by:
Hello, exploring more and more the .NET framework I've seen that threads are often employed by the framework, for example in: - callback methods on timers - async operations (async receives...
4
by: Matthew Groch | last post by:
Hi all, I've got a server that handles a relatively high number of concurrent transactions (on the magnitude of 1000's per second). Client applications establish socket connections with the...
5
by: Droopy Toon | last post by:
Hi, I am using asynchronous socket (BeginAccept for example). I tried to name each thread I am using but threads created by asynchronous Socket functions (like BeginAccept) creates "anonymous"...
25
by: JC | last post by:
Hi People, Please I need your help. This code run a thread ok but Not close later. thanks... private void RunServer(int aPortNumber) {
7
by: Sin Jeong-hun | last post by:
Hi. I'm writing a Client/Multi-threaded Server program on Windows Vista. It worked fine on Windows Vista, but when the server ran on Windows XP, I/O operation has been aborted because of either...
3
by: John Nagle | last post by:
There's no way to set thread priorities within Python, is there? We have some threads that go compute-bound, and would like to reduce their priority slightly so the other operations, like...
10
by: Frankie | last post by:
It appears that System.Random would provide an acceptable means through which to generate a unique value used to identify multiple/concurrent asynchronous tasks. The usage of the value under...
10
by: Paul E Collins | last post by:
I want to fill an ImageList with bitmaps for a ListView from another thread, because it's a time-consuming process. I expect the ListViewItems' images to "load" one by one, as in a Web browser. ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
tracyyun
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.