|
Hello everyone,
I am confused about the statement from the book Threading in C# about thread priority,
http://www.albahari.com/threading/
the confusing statement is, "The ideal solution is to have the real-time work and user interface in separate processes". Why the solution works and ideal?
The whole paragraph is,
--------------------
If the real-time application has a user interface, it can be undesirable to elevate the process priority because screen updates will be given excessive CPU time – slowing the entire computer, particularly if the UI is complex. (Although at the time of writing, the Internet telephony program Skype gets away with doing just this, perhaps because its UI is fairly simple). Lowering the main thread’s priority – in conjunction with raising the process’s priority – ensures the real-time thread doesn’t get preempted by screen redraws, but doesn’t prevent the computer from slowing, because the operating system will still allocate excessive CPU to the process as a whole. The ideal solution is to have the real-time work and user interface in separate processes (with different priorities), communicating via Remoting or shared memory. Shared memory requires P/Invoking
the Win32 API (web-search CreateFileMapping and MapViewOfFile).
--------------------
thanks in advance,
George
|
|
|
|
|
It tells you right there in the paragraph...
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Thanks Paul,
After some thinking, I think it just means that for RT task you want to set process and thread priority to maximum.
If you have a UI thread in the same application - you can lower the thread priority, but process priority will still be high, giving unneded CPU cycles to the UI thread
So best solution will be extract UI to another process that can have independent process and thread priorities so no additional CPU cycles will be wasted on UI tasks.
Understanding correct?
regards,
George
|
|
|
|
|
George_George wrote: you have a UI thread in the same application - you can lower the thread priority
You run the risk of your application being not very responsive. With current multi-core machines, I suspect this really won't be an issue anymore, for the most part.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Thanks Paul,
With multi-core H/W, is there any method to assign some thread to run one some CPU (in other words, let the specific CPU serves the specific thread)?
regards,
George
|
|
|
|
|
This google search [^] on thread affinity may answer your question...
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
|
George_George wrote: is thread affinity relates to my question?
You also asked about assigning a thread to a specific CPU, and that is where thread affinity comes into play...
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
|
Our beta testers have been reporting a bug that I can't figure out. The only stack trace that comes back is:
System.Threading.ThreadAbortException: Thread was being aborted.
at System.Windows.Forms.NativeWindow.DefWndProc(...)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(...)
at System.Windows.Forms.NativeWindow.Callback(...)
What's strange about the stack trace is that it appears to only involve Windows.Forms code and none of our own code. We do have worker threads that occasionally get aborted, but no matter how hard I try to simulate the error by aborting threads or throwing exceptions in random places, I can't get a stack trace that looks anything like that.
Does anyone have an idea of what might cause a stack trace that looks like that?
|
|
|
|
|
If you abort a thread, the stack trace can contain pretty much anything. If it looks like what you posted, it simply means that the thread was aborted while running code in the main method of the thread.
When a thread is aborted the ThreadAbortException is thrown in the thread. To handle this as gracefully as possible, your thread should catch this exception in the main method, release any resources that the thread uses, and then just return.
The best is of course never to abort threads, but instead set a property or something like that, and let the thread finish itself off. Then it's much easier to write code that releases the right resources.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks for the comment! One of the things that baffles me is that the stack trace appears in an "Unhandled exception has occured in your application" window. Simply aborting a thread has never caused such a message to appear.
|
|
|
|
|
Another thing that's confusing about it is that the stack trace looks like it's the GUI thread that's being aborted...but that's certainly not the case.
|
|
|
|
|
i created a design with labels, textboxes and
(dropdownbox in list format) but do not know how to make my dropdownbox be in databinding instead of list format.
|
|
|
|
|
Here[^] is something you need to read.
Any control that can be databound, has a DataSource property. Set it to any valid source, such as a string array, or a list.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I thought maybe it was a datatype conflict and i checked the data type and the 2 variables are of the same data type but even when the conditions true, the if loop is not executed. heres the code and they are saved in 3 different files and here i am using interface to implement an ADT. And i am executing this code in Visual C# 2008 express edition. Can someone help e with this please, check he if condition.
<pre>
// File Name: ISet.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public interface ISet
{
int Cardinality
{
get;
}
void Add(Object element);
void Remove(Object element);
}
//File Name: Set.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class Set:ISet
{
private Object[] set1;
public int MAX = 20;
private int cardinality;
public Set()
{
this.set1 = new Object[MAX];
this.cardinality = 0;
}
public int Cardinality
{
get
{
return this.cardinality;
}
}
public void Add(Object element)
{
this.set1[this.cardinality] = element;
cardinality++;
}
public void Remove(Object element) //convert the set[i] to interger
{
Console.WriteLine("the element to be removed"+element);
for (int i = 0; i < this.cardinality; i++)
{
Console.WriteLine("The element in the set" + set1[i]);
Console.WriteLine("The element passed as the parameter" + element);
Console.WriteLine(set1[i].GetType());//checking the datatype;
Console.WriteLine(element.GetType());
if(set1[i] == element)
{
Console.WriteLine("The element to be removed found!!");
//This statement is not executed even when the condition is true!!!!!!
}
} //closing for loop
} // function end
} //end of the class
//File Name : Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
Set set1 = new Set();
Console.WriteLine("The number of items in the set:" + set1.Cardinality);
set1.Add(5);
Console.WriteLine("The number of items in the set:" + set1.Cardinality);
set1.Remove((5));
}
}
</pre><pre></pre><pre></pre><pre></pre><pre></pre>
|
|
|
|
|
|
so sorry about that i was referring to if condition?? somehow when the if condition is true the statement "The element to be found!" should have printed but it is not doing so. Is something wrong with the compiler? because the code looks fine to me too.
|
|
|
|
|
set1[i] == element
I suspect this isn't doing what you want; perhaps element.Equals ( set1[i] ) will do it.
|
|
|
|
|
I'm working on a set of classes to simplify the use of sockets, however I have a problem: I don't know how to use sockets. Does anyone know of some good, easy to understand tutorials for server end and client end sockets?
Thanks.
|
|
|
|
|
How can you simplify something you don't know how to use? That's like saying I'm trying to simplify using a screwdriver, but I don't know what a screw is.
Anyway, search for articles on CP and google.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
If I can find a good tutorial on sockets I can create a set of classes to simplify the use and creation of sockets which I can use in the future.
|
|
|
|
|
Hello,
Is it possible to close a messageBox automaticly after few seconds?
Any one can help me?
Thanks
PC
|
|
|
|
|
You could but it would involve making your own class to use as a messagebox because the MessageBox class is static so you can inherit it and when you show it the code stops till you click OK.
Feel free to prove me wrong anyone.
|
|
|
|
|
Your best bet is just to write your own messagebox that does this.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|