|
Thanks for the link.
I had read this before but do not really understand it.
Thanks
|
|
|
|
|
Sometimes computers need to things which must finish before or at a particular time, or length of time. Sometimes real-time systems are very important and will result in bad things happening if they do not work. Anti-lock brakes on a car are an example of a real-time computing system it would be bad if the system, did not release the brakes at the correct times as it might mean the car will crash and people going to hospital.
Some real time systems are not allowed to be naughty at all and cannot miss one deadline as this is a failure, some are allowed to be a little bit bad and miss some deadlines because missing a deadline is not too bad as the computer's answer can be ignored, some systems can miss lots of deadlines but the information they give is more useful the closer it is to the deadline.
Some people mix up real-time and high performance: A supercomputer doing hard maths is peforming well but not working in real time. The anti-lock brake doesn't have much to do before it reaches it's deadline so it's performance is not high, but it does have to finish before the deadline, so it is real time.
|
|
|
|
|
arkiboys wrote: What is a realTime application?
It is a system where response time is of most importance. We all have performance related requirements but the application does not fails if those are not met. For real time, processing time is one of the requirements.
arkiboys wrote: Is it one with multithreading?
Not all multi-threaded applications are real time. IMHO threading and real time do not relate.
arkiboys wrote: If an application uses background worker process, can it be a realtime application?
Yes. If the background thread does the work and reports back to the main thread within the time limits, it can be.
Note after Keith's reply: A real time application does not mean that it is very fast with processing. It means that it always processes within the given time limit. If it does not, it is a failure.
"The worst code you'll come across is code you wrote last year.", wizardzz[ ^]
modified on Monday, May 16, 2011 5:02 PM
|
|
|
|
|
d@nish wrote: It is a system where response time is of most importance. We all have performance related requirements but the application does not fails if those are
not met. For real time, processing time is one of the requirements.
I just think it is worth clarifying as it can be read two ways IMO: It is not the fastest possible response time that is the issue (though often real-time systems do need good response times) it is more the time of the response to meet a deadline that defines a real-time system.
(for the OP's benefit)
If you are writing software to process the image on a TV sceen in real time, the image must be ready before the screen refreshes at its regular interval. Lets say the screen is 60 Hz, that means you have 1/60th of a second to get ready. If the code is guaranteed to finish in 1/59th of a second, that is good enough, you do not need to write a higher performance processing route for screen. There are reasons you might write a better performing routine (e.g. support for higher end screens) but you don't need to for this screen.
|
|
|
|
|
True. Updated the reply. Thanks.
"The worst code you'll come across is code you wrote last year.", wizardzz[ ^]
|
|
|
|
|
A video game is a real-time application. Maya is not. Well, Maya does provide real-time 3D modeling, but the final rendering usually takes a while (e.g., it can take hours to render a single frame), so is not real-time.
A real-time application is usually defined as an application which responds immediately to user input. It can be broader, but that is typically what people mean.
|
|
|
|
|
arkiboys wrote: What is a realTime application?
depends on what real-time means to you.
hard real-time? soft real-time? what is your time resolution?
how bad is it when a dead-line isn't met? If your analog video recorder skips a frame, you can still enjoy the movie.
if your app is all about some physical events happening at 100 microsecond intervals or less, a Windows PC probably is not the solution, unless you add intelligence, say some micro-controller based subsystem with a real-time OS or no OS at all.
whatever definition you use for real-time, you will have to configure your PC accordingly. Windows Update and automatic reboots won't be welcome...
Multi-threading is in another dimension. It may or may not be present, wanted, or required, in a R-T app; although probably interrupt handlers are more likely than threads. The .NET ThreadPool (and the BackgroundWorkers that are based on it) behave pretty unpredictably time-wise, so they would not fit in a R-T app.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hello,
I would use a ThreadPool like this :
public void TEST()
{
Object oMissing = System.Reflection.Missing.Value;
Object oTrue = true;
Object oFalse = false;
Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
oWord.Visible = true;
oWord.Visible = false;
Object oTemplatePath = @".\1.doc";
oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
{
if (range.Text.Trim().Contains("P"))
{
int pos = range.Text.Trim().IndexOf("P");
string str = range.Text.Trim().Replace("P", "");
range.Text = str;
}
}
Object oSaveAsFile = "./2.doc";
oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
oWordDoc.Close(ref oFalse, ref oMissing, ref oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
}
static void Main(string[] args)
{
Program test = new Program();
ThreadPool.QueueUserWorkItem(o => test.TEST());
}
Unfortunatly it don't work.
Thank you verry mutch.
|
|
|
|
|
What do you mean by the ThreadPool doesn't work? What, exactly, is going wrong - apart from the fact that your program will exit here before your application gets a chance to do the work in the ThreadPool?
If you are going to queue an item, you've got to give it a chance to complete before the program exits. Immediately after you call QueueUserWorkItem , your code exits. I would suspect that this is your problem.
|
|
|
|
|
Thank you verry mutch for your answer, the TEST method isn't executed, I do not get the document word.
I want to spend a block of code to run heavy, however the code does not return anything, thank you for your feedback on my big problem.
|
|
|
|
|
Teacher: Ok, class... For this quiz, you're going to go through this document and cross out all of the P's... Ready... set... GO! Time's up! Pencils down...
Class: But we haven't started yet...
Teacher: Pass your tests forward now!
|
|
|
|
|
Ian Shlasko wrote: encils down...
FTFY.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Its not going to execute and its not expected to. As Pete indicated, your application exits BEFORE the Test method has a chance to run. You need to wait on your main thread for the worker threads to finish.
|
|
|
|
|
How i can wait the end of execution ?
|
|
|
|
|
As I said, when you run something in a background process, you need to wait for it to complete. A simplistic mechanism here would be to use a Monitor to wait for the document method to complete - although in this case, I have to question why it's a background task at all. Architecturally, you'd be better off having the task run on the main thread and then exit.
|
|
|
|
|
exactly, whene i put Thread.Sleep(10000); the TEST method was excuted, so i need to wait the time necessary for executin my method, it's possible?
|
|
|
|
|
Why don't you just call it without threadpool?
|
|
|
|
|
i would excute the TEST method 5X in the same time, how in can do this?
|
|
|
|
|
If you're executing the same method 5 times together, you're probably going to get a conflict when you try to save the document.
|
|
|
|
|
Looks like you could really use some study on threading since you seem to not understand what the others are telling you.
There's lots of books on the subject, but for free there's always the documentation at MSDN: Managed Threading[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
i would usoont the threading pool because there ara many advantages, like the memory using, i dont have visual studio 2010, i work with 2008, thank you for answhering me.
|
|
|
|
|
abbd wrote: i would usoont the threading pool because there ara many advantages, like the
memory using
Eh? What memory advantages?
abbd wrote: i dont want using thread
Ultimately, if you are using the ThreadPool, you are using threading. It's just that the gory details are hidden from you - as is the fine grained control you get if you manage the threading yourself. Seriously, read up on threading. It's a tricky concept to master, and you are just storing up trouble for yourself if you attempt to use it without a detailed understanding of it.
|
|
|
|
|
you don't need .NET 4.0 to get good multi-threading, you can do it easily since 2.0, provided you understand how it works. Hit the books and study. Now stop asking to be spoon fed.
Warning: I'm not sure the Office PIA behaves well in multi-threading of any kind, I'm not saying it won't, I'm saying I have some doubts.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Monday, May 16, 2011 6:25 PM
|
|
|
|
|
Hello,
I try for :
Object oMissing = System.Reflection.Missing.Value;
Object oTrue = true;
Object oFalse = false;
Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
oWord.Visible = true;
oWord.Visible = false;
Object oTemplatePath = @".\1.doc";
oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
{
if (range.Text.Trim().Contains("P"))
{
int pos = range.Text.Trim().IndexOf("P");
string str = range.Text.Trim().Replace("P", "");
range.Text = str;
}
}
Directory.CreateDirectory(@"F:\PS-IN\"+threadContext);
Object oSaveAsFile = @"F:\PS-IN\" + threadContext+"\\" + threadContext + ".doc";
oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
Console.WriteLine(threadContext+" "+DateTime.Now.ToShortTimeString());
oWordDoc.Close(ref oFalse, ref oMissing, ref oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
}
static void Main(string[] args)
{
const int FibonacciCalculations = 50;
ManualResetEvent[] doneEvents = new ManualResetEvent[FibonacciCalculations];
Program[] fibArray = new Program[FibonacciCalculations];
Random r = new Random();
Console.WriteLine("launching {0} tasks...", FibonacciCalculations);
for (int i = 0; i < FibonacciCalculations; i++)
{
doneEvents[i] = new ManualResetEvent(false);
Program f = new Program();
fibArray[i] = f;
ThreadPool.QueueUserWorkItem(f.TEST,i);
}
WaitHandle.WaitAll(doneEvents);
Console.WriteLine("All calculations are complete.");
}
it generate the 50 word files, but he never leaves the wait, thank you for your help.
|
|
|
|
|
Do you ever set doneEvents members to true? If not, how can you expect the wait to ever succeed?
Please think about what you're doing before posting a code dump here. If you don't understand how threading and wait handles work, please read up on them before trying to use them.
|
|
|
|
|