It depends on how you set the Visual WebGui timeout as 40 minutes, and what you want to accomplish.
If you for instance have the default session timeout as 20 minutes, and you set the Visual WebGui's KeepConnectedInterval to any value above 20 minutes, you would get session abaononed before the Visual WebGui application timeouts.
Keeping the 20 minutes sessionState timeout, and setting the Visual WebGui's KeepConnectedInterval to a lower value, would keep the session alive as long as the KeepConnectedRequests keep firing more frequently than once every 20 minutes. After the last KeepConnectedRequest is fired, the session will be abandoned 20 minutes later, again assuming the default of 20 minutes sessionState timeout.
One way of forcing the session to be abandoned at the same time the Visual WebGui application times out, might be to have the Visual WebGui's timeout page redirect to a Visual WebGui "timeout form", which could then make sure the session was abandoned and redirect somewhere else.
Hope this explains,