Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<CANCEL> or <SUSPEND> buttons 2

Status
Not open for further replies.

Ildegardo

Technical User
Feb 23, 2008
12
IT
I need some suggestion on the following issue:
working on judge databases and having to handle a lot of informations on them, sometimes happens that a job started with a PRG lasts many hours before it is completed (I arrived frequently to exceed 12 hours).
The only option I have used till now to stop these routines is to leave the user the option to press the ESC key. This is because I’m not able to feel any CLICK event on any button while a PRG is running.
Can you suggest any way allowing to feel, inside a PRG, the CLICK on a potential <CANCEL> or <SUSPEND> button, allowing therefore to handle the user’s decision to finish the job?
Thank you in advance
Ildegardo
 
12 Hours? What is taking so long? Anyway to optimize?
Any way to make the prg and exe, and at least take it out of VFP IDE.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Mike,
I do not understand if the second portion of your response to my post (the first portion I do not even consider) should be intended as a criticism.
If it is, please be informed that I would have considered more professional and more polite the link to the FAQ where you think should be a response to my question, letting me make the consequent deductions.
Now after your response, I’m still not having an answer to my question and leave to you to deduce my opinion on you.
Regards.

Ildegardo.
 
I cannot really understand why the only answer people are able to give to my question is a comment on the time some routine lasts to complete its job.
I’m not prepared to explain why I’m facing this situation. But everyone might imagine that in front of such condition I spend a lot of time in verifying all possibilities to reduce the job time.

Finally: is there some people able to respond to my question avoiding to comment on the time required to complete the job?
Thank you very much in advance to this person(s)
 
Ildergardo:

Mike Yearwood give you the answer. put SET ESCAPE ON at the begining of your program. BUT I have found its not a 100% effective. But try the following and adapt to your needs...

SET ESCAPE ON
DO WHILE .t.
WAIT WINDOW " stop" NOWAIT noclear
ENDDO

Now when you press Escape, the loop will stop

Good Luck
 
Have you tried using DOEVENTS, or DOEVENTS FORCE? On the one hand, that may give you the opportunity to handle button clicks, or other events, but on the other hand, please be aware that it will further increase, especially if you use the FORCE option, the overall processing time.



--------------
Good Luck
To get the most from your Tek-Tips experience, please read
FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
To go back to the original question ...

Ildegardo, I understand your concern about the user hitting ESC. Personally, I only have ESCAPE set on during development. I don't think it's appropriate in a production system.

A better option is to display a form with a Cancel or Pause button. However, if you do that, you need to add DOEVENTS to your main processing loop. The point is that the application won't be aware of the user's clicks until it next executes DOEVENTS. So you need to execute that command fairly frequently within the processing.

It's not a perfect solution. The chances are that the user will see a small delay between clicking the button and seeing a response. Also, you can't prevent the application from displaying an hourglass while the process is running (as far as I know), so it might not be obvious to the user that they are free to click.

Just to add .. please don't be offended by the people who questioned the fact that the process takes so long to run. It's true that that has got nothing to do with your question. But, to be honest, if a client came to me with the problem that you presented, my first reaction would also be to question the length of the process.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
==> We cannot accept things taking 15 minutes much less 12 hours.
We have no idea what this process is doing, nor how it works. Maybe it can be done faster, but then again maybe not. Maybe the judge wants it done that way. How do we know? We don't. I agree that any process that takes that long should be evaluated but if it's a Towers of Hanoi type problem, or one with a combinatorial explosion, it may just take that long. There are problems that takes hours to solve.

Yes we are programmers, and we're always looking for the fastest and most efficient way of doing things. It's only natural for use to look for creative ways to solve problems, even if it means redefining the problem. To be sure, many times, redefining the problem can be very effective, and in the end, that course sometimes makes the question moot. That could very well happen hear. nut we don't always have that luxury. Sometimes we have to play the hand we're dealt, and that means simply doing our best to answer the question being asked.


--------------
Good Luck
To get the most from your Tek-Tips experience, please read
FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Ildegardo - I think the "comment" that offended you was Mike Gagnon's signature that points people to the FAQ. It wasn't aimed at you in particular. It's part of every message he posts here, that's why it followed his name.

As for your actual problem, DOEVENTS is the ticket, but like the others, I suspect the process could be made faster.

Tamar
 
Ildegardo,
In this forum there are as far I have experienced many MVP's (if you know what that means). So I believe you can't have a better place for getting help. It's just a matter of giving right questions.
I am not happy to say but talking about 'professional and polite' I think you probably need a mirror instead of complaining about lack of answers?
Pls. read all replies carefully and keep in mind that all here in this forum are spending time in trying to solve your problem.
KR
-Bart
 
==> I've taken to asking what the real problem is. ;)
==> It's just a matter of giving right questions.

Wow, tough room.

I hope that if and when I need to ask a question that the MVP's here will give me at least some benefit of the doubt that I'm asking a "right" question.


--------------
Good Luck
To get the most from your Tek-Tips experience, please read
FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Ildegardo:

I have been programming for 15 years and am happy for anyone to question my code to get me thinking. Noone here is trying to put you down but only trying to get at the root of the problem. These guys here are experts at what they do and are used to someone pointing in the wrong direction for a solution. I for one work on a help desk for a financial institution where the business users often tell us 10% of the details they know about a given problem. They, like you, sometime get offended when we ask questions. Often times asking the questions gets the users thinking and they end up solving their problem. Other times just getting all the details simply gives us the tools to give the users an intelligent answer.

Please look at other questions asked in these forums and you will find the same type response. They are only trying to help.

My wife's car wouldn't start last week so she asked me to look at it. It was turning over, battery voltage was ok, spark ok, fuel gauge showed 1/8 tank. After checking all this I asked if something happened to the car yesterday.
Any new noises? Anything unusual, etc. Oh, ya she said... She ran out of gas so coasted into the driveway! And the fuel guage? She said that's been broken for a while. And why didn't she tell me all this? She assumed I would know
all this 'cause I always work on her car when something goes wrong...

PS: Some of our monthly and quarterly routines run all night.

Michael Ouellette
 
Sorry for not having been able to react till now. The last 2 days I was not here and therefore I’m able to replay only today.
Please understand this message addressed to all people who has replied.

First:
My first reaction was due to the fact that I saw at the end of one replay to my question the message “… to get the best response to a question, please check out FAQ184-2483: How to get the best response from the forum first…”. This was interpreted from my side as a “direct” criticism to my question, since the subject was already available on FAQ.
You probably already remarked that I’m new in this group and did not recognize before, that a lot of you are putting such kind of messages in their signature.
May I suggest to the people who are doing that to erase them?
This website is very well organized, and I feel that all these “directions” are already “evident” to every person approaching it, since they are quite clearly explained and outlined in the website lay-out and in the guidelines for posting. To “repeat” them again in the signature might be interpreted as an appreciation on the content of the post you are responding.

Second.
I recognize the experience of every person responding. If I wouldn’t do that I did not even post the question!
But, again, also every person who is reading a question must assume that the guy who is gone to post already “analysed” its situation and is just in need of help. I make a clear difference between “curiosity” and “comments”. While I can understand and accept curiosity, please avoid comments: they are frustrating!

Anyway to explain why my job lasts more then 12 hours (and not 15 minutes), consider that it is aimed to check on a system based on around 150.000 items, with a medium complex BOM (5 to 10 levels – around 900.000 records) and an average standardization (common components used in the different sale items), for EVERY SINGLE ITEM
- which quantity is hold in stock (12,000 references)
- which quantity has been used on items sold in the last 12 months (around 25,000 references), divided by month
- which quantity is booked for sales orders (15.000 references)
- which quantity has already entered the WIP
- which quantity is on order by suppliers.
- which quantity is forecasted to be used next 12 months (using weighted rolling average and linear regression)
and few more “indicators” which would be complex to detail, and which involve to count the number of Customers who bought references using the reference currently in process.
All files used during the job are indexed and related each other.
Hope this explain.

Regards to everybody.
 
Ildegardo,

the answer is DOEVENTS or DOEVENTS FORCE, which must be done frequently in the long processing. Sometimes it's not even enough and a click on a cancel might still not be recognized, if for example within the long running process there are SQL-Statements each taking minutes, a click might be reacted to only after those minutes, nothing satisfactory.

The solution should be to cancel the process from another process. So you should write a programm that executes your process via CreateProcess(), then your Form, which may be showing the progress could react to the Cancel-Button ad once, and use seomthing as KillProcess to kill the long running process.

Take this as an example:
The main loop rinning in this code is calling WaitForSingleObject, to wait if the created process stopped. Each call waits 5 seconds and if the process is still running displays that. You can lower that intervall to 0 so WaitForSingleObject instantly returns the status of the process and then do the DOEVENTS to be able to react to a click.

With the details you gave about processing each single ITEM. Be aware that with a single SQL you can COUNT(), SUM() etc. on different Items by using the GROUP BY, so perhaps your process is better off not processing each single item in the outer loop, but each different single result information you want on all items. Normally this is more effective. I understand that without an insight on the matter one really can't say what's best of course.

Bye, Olaf.

Bye, Olaf.
 
Ildegardo - thanks for providing more information about what you're doing. Based on the numbers you cite, I think there probably are ways to speed your process up. While that's a large database, it's not huge by VFP's standards.

Are you doing this with Xbase code or with SQL code? If it's SQL code, have you used SYS(3054) to see what kind of optimization you're getting?

Probably most importantly for the kind of process you describe, have you organized that steps so that you perform each calculation once and, if you need it again, use the previously calculated result.

Just to give you something to think about, I keep a table with 1.1M records in it around for this kind of testing. I just tried a query that counted the number of items of each type (about 1000 different types) for that table, and it ran in 10 seconds with no index tag on the field I was grouping.

Tamar
 
Sorry. I continue replay because I understand that many of you are interested in knowing more about “my troubles”.
But, and I’m sorry for that, this is my last replay, because I cannot say anything else and I'm specially intended to show that, sometimes, to detail the “environment” of a problem is annoying and probably taking away from the problem itself (still remember that my question was: “… is it possible to feel a CLICK EVENT while a (long lasting) PRG is running?… “)

My process is running batch.
This means that all necessary archives (list of references, BOM, invoices, WIP, Customer orders, Purchase orders) are loaded once, at the beginning of the job. They are coming from a SAP environment and are provided as TXT/CSV files. To load the archives, indexing, cleaning, and relating each other takes no more then 2 minutes. The process is then producing outputs which are NOT “returned” to SAP.
The big deal in the job is the “implosion” necessary for every single item. I believe you are familiar with this process.
The database I’m processing (150000 items of which only 7000 row material), due to the complexity of the BOM (5 to 10 levels), and the level of standardization (again 150000 items of which only 7000 row material), is producing, as an average for every single item processed a list of 20 – 25000 references. For every reference I need to check
- if sold (if yes how many – by month the last 19 months). This I call “usage”
- if booked how many I have delayed and how many I have on order for this month
- how many I have purchased
- how many I have delayed on purchase order
After this need to summarize the “usage” “rolling 12 months” for the last 7 months, and use this numeric base to calculate:
- 2 linear regressions
- 2 weighted averages
- 2 medium averages
Please do not ask me why “2” for the last 3 steps, because it will be too long.

Does it explain?

Probably something can be done in the implosion process. I use a criteria normally used on softwares oriented to manufacturing.
I’m afraid in changing because a small mistake in this process might cause big troubles. However I’m ready to accept suggestions.

 
With the information you've provided, it's hard to make specific suggestions. My first thought would be for you to add some timing code that produces a text file for you to review. Then, after the next time you use this code, you can see exactly which parts are slow and focus your attention on those parts.

In addition, you might consider building a smaller data set to test on (since testing any 12-hour process is clearly not something you're going to do much of), and use that to see if you can track down the slow parts.

Tamar
 
Ildegardo,

please don't get frustrated because people not just concentrate on your main question. And please take note, that I did answer it. If you have questions on the idea of running your lengthy comutation as a seperate process you monitor from a controlling process, fel free to make aditional comments or questions.

In what you described in more detail, you process data of a time window of one last year, which moves one day each day. If you do that every day, most of the data stays the same, the changes between last days time window and this day is that data of one day disappears and data of the actual date is added. That alone would enable you to reuse and adjust many computations just by the data of that disappearing day and the new day, instead of recalculating from scratch every time.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top