1. GUSTAVO MARCELINO
  2. PowerBuilder
  3. Wednesday, 11 November 2020 20:42 PM UTC

Hi,

I have a problem with my software in PB 2019 when I use Multithread. It seems that the application becomes "Unstable" when I use Multithread and it crashes randomly. Regardless of whether I run in IDE or executable

Apparently it is in any Thread I use in the Software, but an example that occurs is when I call a thread every 5 seconds to check Ping. After a while, the application stops responding.

Attached is a small application that measures only the ping on a Timer, and if you leave the application running, it will crash within 5 to 10 minutes.

What am I doing wrong, can you help me?

Below is an excerpt of the code:

//window > timer()
string ls_ip_ping

ls_ip_ping = is_ip_ping

SharedObjectRegister("n_shared", is_nm_thread)
SharedObjectGet(is_nm_thread, in_shared)

in_shared.post of_ping(in_callback, ls_ip_ping)

SharedObjectUnRegister(is_nm_thread)

//------------------ in_shared > of_ping
Boolean lb_success
String ls_ipaddress
Double ldbl_elapsed
n_ping ln_ping

ln_ping.of_Performance_Beg()
lb_success = ln_ping.of_Ping(aip_ping)
ldbl_elapsed = ln_ping.of_Performance_End()

if not lb_success then
ldbl_elapsed = -1
end if

a_callback.post of_ping(Long(Round(ldbl_elapsed, 3) * 1000))

//------------------ in_callback > of_ping
if IsValid(iw_thread) then
iw_thread.st_2.Text = String(ping) + 'ms'
end if

Attachments (1)
GUSTAVO MARCELINO Accepted Answer Pending Moderation
  1. Wednesday, 18 November 2020 14:59 PM UTC
  2. PowerBuilder
  3. # 1

Just to provide feedback for future research:

I was unable to solve my needs using the MultiThread that is available in PB. I did several tests in several ways (including what they suggested in the Post's reply) and the app continues to crash randomly.

Remembering that my application makes several different requests per minute, and with each request I use MultiThread to not block the main thread. However, after about 10 to 20 minutes of using the "Stop responding" application.

My solution that solved 100%: I created a DLL in C # (ConnectToNewObject), and in it I make all Asynchronous requests. E When calling this function, I send the Handle of the window in PB by parameter. and in the DLL when I have the result of the request, I call a SendString to the PB.

I don't know if it's the best way, but it worked very well for me and the app never crashed after that.

(Translated by Google Translate)

Comment
  1. Armeen Mazda @Appeon
  2. Wednesday, 18 November 2020 15:07 PM UTC
Thanks for sharing the solution!
  1. Helpful
There are no comments made yet.
Christopher Craft Accepted Answer Pending Moderation
  1. Thursday, 12 November 2020 15:39 PM UTC
  2. PowerBuilder
  3. # 2

Gustavo, 

Couple thoughts:

The first change I would make is to move the SharedObjectUnRegister() call to the close event of the window. You don't want to mark it for destruction until you are done using it.

The other thing is since this is on a timer you could be trying to access the shared object before it has notified the callback object. Since you are using an Instance variable I would move your Register and Get calls to the Open event or wrap a If Not IsValid(is_nm_thread) check around it before trying to register and get it again.

Chris Craft

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.