|
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.
|
|
|
|
|
i find the solution, we must add doneEvents[int.Parse(threadContext.ToString())].Set(); after the and of generation.
modified on Tuesday, May 17, 2011 5:05 AM
|
|
|
|
|
I need to pass parameters (like arraylist,...) to the TEST method, how i can do this ?
I don't understand whay the test methode must have juste the object parameters.
modified on Tuesday, May 17, 2011 5:45 AM
|
|
|
|
|
hi all.
I divide width of row datagridview in c# .
when i set columnHeaderVisible = true: OK
but i set columnHeaderVisible = false: it have been wrong 1 desert = width of row header.
question : when set columnHeaderVisible = false. how i do to width of rows in datagrid not wrong ???
please help me.
code
dataGridView.Height = h*12;
dataGridView.RowTemplate.Height = h;
if dataGridView.columnHeaderVisible = true ==> ok
but : dataGridView.columnHeaderVisible = false ==> not ok
nothing
|
|
|
|
|
Hi,
Okay, I read your question a couple of times, and I have no idea what you just said / asked? Could you please try and be more specific about the problem?
Kind regards,
|
|
|
|
|
You're going to have to define what a correct column width should be for anyone to answer this.
What do you mean by "not wrong"??
|
|
|
|
|
Hi,
How to find out installed MS office 2010 is 32-bit or 64-bit from the registry?
googled and fouind couple of links...but seems not working or do not have the registry key.
thanks.
|
|
|
|
|