Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
8
Erster Beitrag:
vor 12 Monaten
Letzter Beitrag:
vor 12 Monaten
Beteiligte Autoren:
André Labuschagné, Alexandre Leclerc

Call Window From Procedure With Timer

Startbeitrag von André Labuschagné am 24.08.2016 11:55

Hi All

I have found out why the HTML control is not displaying on a window that is called. In this case it is because it is being called from a procedure with a timer active and is running on its own thread. So here is my situation: I need a procedure with a timer to poll a web service. If there is data on the web service it is read. Let us say three records are found there. I then need to call a window displaying these three records. Calling this window does not display the data and actually causes the app to crash when the window is exited. What would be the best way to detect that data has been collected from the web service and the window must be opened? Hope that makes sense.

Cheers
André

Antworten:

Hi André,

Are you in WB or WD?

It should work all right in all cases. You could even use a thread to pool and get the data. Simply open the Window as non-modal (as it would block other processes after). If additional data is available while the window is open, it will not be a problem because all you have to do is refresh the window already opened (as non-modal, of course).

Kind regards,
Alexandre Leclerc

von Alexandre Leclerc - am 24.08.2016 12:27
Hi Alexandre

This is WD. I cannot get it to work. If I call the window fro outside of the procedure with the timer it works and exists fine. If I call it from within the procedure with timer it goes haywire. It does not work. The timer is in a thread of its own as I checked that option.

I am completely lost on this one - have no idea where to start.

Cheers
André

von André Labuschagné - am 24.08.2016 14:26
Hi André,

Do not mix up timers and threads. Just use one or the other. If you use a timer, you are running in the main thread and you can play with the interface. If you use a thread, you cannot interact directly with the main interface. You must do so in another procedure which you will call using ExecuteMainThread() or by checking the “option” in the “timer/thread” section to “Run in the main thread”.

Summary:
—Get your thread to pool for data and get it (in a global class or variable, and declare it with the “critical section” argument [in WD21]).
—If any data has to be displayed call another procedure of yours, from the thread, to do so ShowMessagesInPopupWindow() and make sure you call it with ExecuteMainThread() or the equivalent option checked in that procedure.
—In the ShowMessagesInPopupWindow() make sure to open the window using OpenChild() as you want to interact with that window. In your case, OpenPopup is not a good idea.

Best regards,
Alexandre Leclerc

von Alexandre Leclerc - am 24.08.2016 15:20
Hi Alexandre

Brilliant - I am going to try that right now.

Cheers
André

von André Labuschagné - am 24.08.2016 17:42
Hi Curtis

I am stuck on the first step - how do I get my main thread to pool for data without using a procedure with a timer? I want the pooling to take place every 30 minutes say.

Cheers
André

von André Labuschagné - am 24.08.2016 17:59
Hi André,

In a thread, you do the loop yourself. You can be in an infinite loop forever without worry. Just make sure you make a pause in that loop (ThreadPause, for 30 minutes if you want).

So, in a loop, do the pooling, do any actions afterward, then pause, then loop again.

There are many ways to do what you try to do. This is just one method.

For you popup window, start by mastering its behaviour, then if it works well, put an HTML control if you want after to display the data. Solve one problem at the time. :-)

Best regards,
Alexandre Leclerc

von Alexandre Leclerc - am 24.08.2016 18:29
Hi Alexandre

OK - huge progress here. I am calling the window in the same thread and all is working very well indeed - including the html control. It was definitely a threading and critical section issue.

Another thing that I changed was opening the "popup" as a window and not a child window so that the looping through the messages is suspended until the users clicks on the message. The called window closes by just clicking on it - placed some code in the events there to do that.

So it looks like I have a solution after all.

Thanks to you and Curtis for getting the old brain going again.

Cheers
André

von André Labuschagné - am 24.08.2016 19:08
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.