Oracle APEX - apex_application.g_print_success_message displays the message twice on refresh - oracle-apex-5.1

I am utilizing apex_application.g_print_success_message in one of my APEX processes to display a message to the user.
The process gets executes on page submit when Request=VALUE1.
The code checks if a variable is greater than 0, then displays a message. So the message is supposed to only be displayed when Request=VALUE1 and if :P1_ITEM > 0:
BEGIN
IF TO_NUMBER(:P1_ITEM) > 0 THEN
apex_application.g_print_success_message := 'Test';
END IF;
:P_ITEM := 0;
END;
After displaying the message I set the page item to zero.
I submit the page, process executes, message gets displayed. Everything works fine. But then if I go ahead and refresh the page, the message displays again. Not sure why as one of the conditions is TO_NUMBER(:P1_ITEM) > 0 and I did set it to 0. Also when I do a refresh the request cannot be VALUE1 so I know the process does not get executed. But then why is the message getting displayed again?

Did you try with clear session state process?
Or maybe

Related

watir/ruby waiting for iframe to exist

I have a problem waiting for an iframe to exist on page after entering a date range and I would rather not use sleep. I am using ruby/watir
I have tried solutions like this -
wait_until(10, "iFrame has not loaded") do
#browser.iframe(id: "dtl00_DP1_content").exists?
end
but this simply returns this error - Selenium::WebDriver::Error::NoSuchWindowError: no such window
So how do I wait for an iframe that does not yet exist please?
I am not sure whether you only want to wait for an Iframe, If you want to perform any operation on an element which is present in the iframe, then you could do as I mentioned in my comment.
#browser.iframe(name: "something").text_field(name: "username").set 'raja'
Or If you still wait for an iframe to appear, then write the following code
#browser.wait_until { #browser.iframe(id: "dtl00_DP1_content").exists? }
The above code waits for 30 seconds, but If you want to increase the time to wait, then write the following code, the following code would wait fo 50 seconds.
#browser.wait_until(timeout: 50) { #browser.iframe(id: "dtl00_DP1_content").exists? }

MsWord.BackgroundPrintingStatus

I have an instance of a word document running (opened through a New Word.Application). I have populated the document and sent it to print, however, if i then use the Msword.application.quit method as the next statement it cancels the print job
I have put in a do while MsWord.BackgroundPrintingStatus = 1 loop in but this then goes into an infinite loop.
stepping into the code and giving the print job time to run before continuing to the quit command works fine and the MsWord.BackgroundPrintingStatus does return to 0.
Why would a do while loop go into an infinite loop while waiting for the status to change?
OK found a way to do it. put the quit in a do while printingstatus = 0

Watin OwnTableCellCells.Count index out of range sometimes

I'm using 20.20.1089, and I'm getting an exception sometime while looping over
like this
foreach (TableRow row in table.TableRows)
{
for (int i = 0; i < row.OwnTableCells.Count ; ++i)
{
// EXCEPTION INDEX OUT OF RANGE
TableCell cell = row.OwnTableCells [i];
}
}
Under the debugger, row.OwnTableCells.Count is 0, but the loop index i has been
increments. I can get Exception:Object reference not set to an instance of an
object.
This happens sometimes only, which is the puzzling part.The webpage is always refreshing automatically after a few seconds. Could this
be the cause of it? Is there a way to disable the cache?
Robin
PS. I'm trying to get this posted on Watin mailing list but it seems the moderator is gone missing, and not approving any new registrations.
Hi your mail was send on the mailing list as well, but for record sake I'll post my answer here as well.
The webpage is always refreshing automatically after a few seconds. Could this
be the cause of it?
This indeed is your problem. Following one of the possible scenarios to show you how things can go wrong:
1 - calling row.OwnTableCells.Count => returns the number of elements currently on the page
2 - refresh timer triggers page refresh => page reloaded
3 - due to refresh the row.OwnTableCells collection will return no elements any more since the row which was referenced no longer exists on the page. You might still see the same row in the browser, but that is a new DOM row object created after the page refresh. In your code you/WatiN is still referencing the old row object.
So you should change your logic to take this refresh of the page into account.
HtH,
Jeroen

Dialog not available within 60 seconds

I am trying to use Dialog handler twice in a function. For first time it executes well but on second time it hangs the system with dialog box open and showing Ok and Cancel butoon but never able to click it. Also it times out with an error "Dialog not available within 60 seconds"
Dim cdhPopup As ConfirmDialogHandler
cdhPopup = New ConfirmDialogHandler()
If (ie.Button(Find.ById("btnDelete")).Exists) Then
'Cancel the booking '
ie.AddDialogHandler(cdhPopup)
ie.Button(Find.ById("btnDelete")).ClickNoWait()
cdhPopup.WaitUntilExists()
cdhPopup.OKButton.Click()
ie.WaitForComplete() 'Wait for page to finish loading '
Else
Assert.Fail("Could not found the Cancel Button")
End If
Using this at 2 places in my code, First time it executes fine and second time within same function it gives dialog not available whereas it is available error.
My best guess is that in the second pass you are again calling
ie.AddDialogHandler(cdhPopup), thereby registering it a second time, which is somehow crashing the program when the handlers are invoked (cross thread access to internal variables maybe?)
You should perform a check if the handler is registered, and only register it if it isn't.

PostMessage occasionally loses a message

I wrote a multi-threaded windows application where thread:
A – is a windows form that handles user interaction and process the data from B.
B – occasionally generates data and passes it two A.
A thread safe queue is used to pass the data from thread B to A. The enqueue and dequeue functions are guarded using a windows critical section objects.
If the queue is empty when the enqueue function is called, the function will use PostMessage to tell A that there is data in the queue. The function checks to make sure the call to PostMessage is executed successfully and repeatedly calls PostMessage if it is not successful (PostMessage has yet to fail).
This worked well for quite some time until one specific computer started to lose the occasional message. By lose I mean that, PostMessage returns successfully in B but A never receives the message. This causes the software to appear frozen.
I have already come up with a couple acceptable workarounds. I am interesting in knowing why windows is loosing these messages and why this is only happening on the one computer.
Here is the relevant portions of the code.
// Only called by B
procedure TSharedQueue.Enqueue(AItem: TSQItem);
var
B: boolean;
begin
EnterCriticalSection(FQueueLock);
if FCount > 0 then
begin
FLast.FNext := AItem;
FLast := AItem;
end
else
begin
FFirst := AItem;
FLast := AItem;
end;
if (FCount = 0) or (FCount mod 10 = 0) then // just in case a message is lost
repeat
B := PostMessage(FConsumer, SQ_HAS_DATA, 0, 0);
if not B then
Sleep(1000); // this line of code has never been reached
until B;
Inc(FCount);
LeaveCriticalSection(FQueueLock);
end;
// Only called by A
function TSharedQueue.Dequeue: TSQItem;
begin
EnterCriticalSection(FQueueLock);
if FCount > 0 then
begin
Result := FFirst;
FFirst := FFirst.FNext;
Result.FNext := nil;
Dec(FCount);
end
else
Result := nil;
LeaveCriticalSection(FQueueLock);
end;
// procedure called when SQ_HAS_DATA is received
procedure TfrmMonitor.SQHasData(var AMessage: TMessage);
var
Item: TSQItem;
begin
while FMessageQueue.Count > 0 do
begin
Item := FMessageQueue.Dequeue;
// use the Item somehow
end;
end;
Is FCount also protected by FQueueLock? If not, then your problem lies with FCount being incremented after the posted message is already processed.
Here's what might be happening:
B enters critical section
B calls PostMessage
A receives the message but doesn't do anything since FCount is 0
B increments FCount
B leaves critical section
A sits there like a duck
A quick remedy would be to increment FCount before calling PostMessage.
Keep in mind that things can happen quicker than one would expect (i.e. the message posted with PostMessage being caught and processed by another thread before you have a chance to increment FCount a few lines later), especially when you're in a true multi-threaded environment (multiple CPUs). That's why I asked earlier if the "problem machine" had multiple CPUs/cores.
An easy way to troubleshoot problems like these is to scaffold the code with additonal logging to log every time you enter a method, enter/leave a critical section etc. Then you can analyze the log to see the true order of events.
On a separate note, a nice little optimization that can be done in a producer/consumer scenario like this is to use two queues instead of one. When the consumer wakes up to process the full queue, you swap the full queue with an empty one and just lock/process the full queue while the new empty queue can be populated without the two threads trying to lock each other's queues. You'd still need some locking in the swapping of the two queues though.
If the queue is empty when the enqueue
function is called, the function will
use PostMessage to tell A that there
is data in the queue.
Are you locking the message queue before checking the queue size and issuing the PostMessage? You may be experiencing a race condition where you check the queue and find it non-empty when in fact A is processing the very last message and is about to go idle.
To see if you're in fact experiencing a race condition and not a problem with PostMessage, you could switch to using an event. The worker thread (A) would wait on the event instead of waiting for a message. B would simply set that event instead of posting a message.
This worked well for quite some time
until one specific computer started to
lose the occasional message.
By any chance, does the number of CPUs or cores that this specific computer have different than the others where you see no problem? Sometimes when you switch from a single-CPU machine to a machine with more than one physical CPU/core, new race conditions or deadlocks may arise.
Could there be a second instance unknowingly running and eating the messages, marking them as handled?

Resources