Welcome Guest Search | Active Topics | Sign In | Register

WebView.LoadHTML Timeout Options
M. Heinsohn
Posted: Thursday, June 18, 2015 11:03:14 AM
Rank: Member
Groups: Member

Joined: 5/6/2015
Posts: 25
Hi,

i've a service that uses your control to callculate html to a picture. That works most time flawless. But sometimes it runs into timeout.
Here is a part from my code (VB.NET) that i use to render

Code: Visual Basic.NET
Private Function FU_GenerateBase64(Loc_html As String, loc_width As Integer, loc_height As Integer) As String
	FU_GenerateBase64 = ""	
	If Cloc_WebView.LoadHtml(Loc_html).WaitOne(1000) = True Then
		Cloc_WebView.Resize(loc_width, loc_height)
		Using Loc_Image As Drawing.Image = Cloc_WebView.Capture(True)
			Using Loc_Bitmap As New Bitmap(Loc_Image)
				Using ms As New IO.MemoryStream()
					Loc_Bitmap.MakeTransparent(Drawing.Color.White)
					Loc_Bitmap.Save(ms, Drawing.Imaging.ImageFormat.Png)
					ms.Position = 0
					FU_GenerateBase64 = System.Convert.ToBase64String(ms.ToArray)
				End Using
			End Using
		End Using
	Else
		SU_Log("Timeout 1000 ms")
	End If
End Function


the Loc_html is filled with a static html text with embedded css. No external sources. The Cloc_WebView is declared once and only destroyed at the end. My problem is how could i avoid the timeout ? What could cause the timeout ?

At the moment i loop 3 times if i get no return. But that doesn't help every time.
eo_support
Posted: Thursday, June 18, 2015 5:48:06 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

Please try LoadHtml(loc_html).WaitOne(3000) instead of looping three times with a 1000 timeout. Ocassionaly the browser engine can get choked up temporarily but if it does not resolve by itself eventually then it would indicate a problem. By keep looking and submitting new request would only make the matter worse. On the other hand, if you WaitOne(3000) but the request is done in only 10 ms, then the function will return immediately and wait no further.

If that still fails often then there must be a problem somewhere else. In that case I would recommend you to wait until after tomorrow. We will have a new release tomorrow so you can try that build first. The build maybe posted later the day so depending on your time zone it may not be posted during your business hour. You can wait until the new release is out and then try the new release to see if it resolves the issue for you. If it still does not resolve the issue for you, you can try to isolate the problem into a test project and send us the test project. See here for test project guidelines:

http://www.essentialobjects.com/forum/test_project.aspx

Once we have the test project, we will look into it as soon as possible.

Thanks!
M. Heinsohn
Posted: Monday, June 22, 2015 6:02:56 AM
Rank: Member
Groups: Member

Joined: 5/6/2015
Posts: 25
I've tried to set up an test but failed to get the same result only got other strange behaviors.
Anyway, i will use now the latest version test live.

Edit: Not at the moment -> licence problem
M. Heinsohn
Posted: Monday, June 29, 2015 2:53:49 AM
Rank: Member
Groups: Member

Joined: 5/6/2015
Posts: 25
Now i've changed the timeout to 3000 and used the latest version, but the problem stays the same :(
I have tried to build a test application but at the moment i don't have rebuild the error condition.

Some other ideas ?
eo_support
Posted: Monday, June 29, 2015 8:04:23 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

Have you tried using ThreadRunner class? As a general rule, you must run a message loop in your worker thread in order for a WebView to function properly in that thread. The ThreadRunner class is provided exactly for this purpose. See here for more details:

http://www.essentialobjects.com/doc/webbrowser/advanced/thread.aspx

Thanks!
M. Heinsohn
Posted: Tuesday, June 30, 2015 5:06:16 AM
Rank: Member
Groups: Member

Joined: 5/6/2015
Posts: 25
Sorry but the thread runner example doesn't compile.
Error Image
looks like the syntax doesn't work with vb.net
eo_support
Posted: Tuesday, June 30, 2015 11:20:25 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

Please change "Function" to "Sub".

Thanks!
M. Heinsohn
Posted: Wednesday, July 1, 2015 4:05:33 AM
Rank: Member
Groups: Member

Joined: 5/6/2015
Posts: 25
Hi,

nope change to sub doesn't help
Error Image
eo_support
Posted: Wednesday, July 1, 2015 9:33:14 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

The sample code uses anonymous delegate syntax to call the following method and the code is valid:

http://www.essentialobjects.com/doc/eo.webbrowser.threadrunner.send_overload_2.aspx

Both Function and Sub will compile in Visual Studio 2013 with .NET 4.5. Using Function you will get a warning because the anonymous delegate does not have a return value. If you have trouble getting the anonymous delegate code to compile, you can just use normal syntax by declaring the code you call with Send inside a separate Sub and then call it with normal delegate syntax.

Thanks!
M. Heinsohn
Posted: Thursday, July 9, 2015 3:32:59 AM
Rank: Member
Groups: Member

Joined: 5/6/2015
Posts: 25
I'v got it run with threadrunner. But now i have more problems cause the rendered image is the wrong. The Image is from previous attempt

Cloc_threadRunner and Cloc_WebView are class declared
trans_html content:
Code: HTML/ASPX
<html>
<head>
<style>
tr.xx3   {background-color:#E13C00}
tr.xx1   {background-color:#8CFFA0}
body     {background-color:#D8D9DA;font-family:Arial,Helvetica,Swiss;margin:0px}
td.mittel{font-size:20px;font-align:center}
td.klein{font-size:10px;font-align:center}
td.gross{font-size:40px;font-align:center}
td.sehrgross{font-size:60px;font-align:center}
td.Leerzeile{font-size:60px;}
</style>
</head>
<body>
<table border=0 cellpadding=0 cellspacing=0 Width="100%">
<tr>
	<td class="Leerzeile"> </td>
</tr>  
<tr class="xx1">
   <td class="gross">SOLL: </td>
</tr>   
<tr class="xx1">   
   <td class="sehrgross">Test1_02</td>
</tr>
<tr>
	<td class="Leerzeile"> </td>
</tr> 
<tr class="xx1">
   <td class="gross">SCAN: </td>
</tr>
<tr class="xx1">
   <td class="sehrgross">2</td>
</tr>
</table>
</body>
</html>


Code: Visual Basic.NET
If CType(Cloc_threadRunner.Send(AddressOf FU_Render, Cloc_WebView, trans_html), Boolean) = True Then
					Using Loc_Image As Drawing.Image = Cloc_WebView.Capture(True)
						Using Loc_Bitmap As New Bitmap(Loc_Image)
							Using ms As New IO.MemoryStream()
								Loc_Bitmap.MakeTransparent(Drawing.Color.White)
								Loc_Bitmap.Save(ms, Drawing.Imaging.ImageFormat.Png)
								ms.Position = 0
								FU_GenerateBase64 = System.Convert.ToBase64String(ms.ToArray)
							End Using
						End Using
					End Using
				Else
					SU_Log(ENU_Log.Fehler, "Timeout 3000 ms")
				End If

	Function FU_Render(trans_webView As EO.WebBrowser.WebView, trans_args As Object) As Object
		Return trans_webView.LoadHtml(trans_args.ToString).WaitOne(3000)
	End Function


i've removed the threadrunner and use LoadHtml( ).WaitOne(3000) direct but now the routine waits every time 3000 ms :(
M. Heinsohn
Posted: Thursday, July 9, 2015 4:12:19 AM
Rank: Member
Groups: Member

Joined: 5/6/2015
Posts: 25
Ok i've update to the last version 2015.1.84.0 the long waiting is fixed. But at the moment when i'm capturing the image direct after .waitone
i got the previous image.

i've fixed it with called it twice and then capture the image but at least i get the correct image.
eo_support
Posted: Thursday, July 9, 2015 9:37:54 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

Yes. You will need to wait for a little bit after WaitOne completes. The reason is WaitOne returns as soon as the loader finishes loading. There is a small time delay between loader finish loading and screen buffer is refreshed. We may add something like "RefreshScreenBufferNow" in the future. But for now you can try to wait for a short period of time (for example 200ms) and see if it resolves the issue for you.

Thanks!
M. Heinsohn
Posted: Thursday, July 9, 2015 9:44:28 AM
Rank: Member
Groups: Member

Joined: 5/6/2015
Posts: 25
Ok, then i will wait for RefreshScreenBufferNow or something equal.

Looks like rendertime for one image is about ~45ms. Twice rendering works during testing here whole time.
eo_support
Posted: Thursday, July 9, 2015 11:41:34 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Great. Glad to hear that the workaround works for you!
M. Heinsohn
Posted: Wednesday, July 15, 2015 2:58:21 AM
Rank: Member
Groups: Member

Joined: 5/6/2015
Posts: 25
Could the new "Added WebView.IsCreated property" help ? .. Or shows it only that the base class webview is ready ?
M. Heinsohn
Posted: Wednesday, July 15, 2015 4:22:09 AM
Rank: Member
Groups: Member

Joined: 5/6/2015
Posts: 25
With the new version i got only timeouts... bad choice
eo_support
Posted: Wednesday, July 15, 2015 4:38:20 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

Do you get time out on LoadHtml or Capture? Can you isolate the problem into a test project and send the test project to us? See here for more details on how to send the test project to us:

http://www.essentialobjects.com/forum/test_project.aspx

Thanks!

M. Heinsohn
Posted: Thursday, July 16, 2015 8:11:01 AM
Rank: Member
Groups: Member

Joined: 5/6/2015
Posts: 25
Sorry, the problem doesn't want to be extracted. why? i don't know. Some colleague tries also with no success.

With the new DLLs and now with threadrunner i get no timeouts. only wrong rendering if i get the picture to early.

Code: Visual Basic.NET
Cloc_WebView = Cloc_threadRunner.CreateWebView



        Cloc_threadRunner.Send(Sub()
                          If Cloc_WebView.LoadHtml(trans_html).WaitOne(3000) = True Then
                            System.Threading.Thread.Sleep(50)
                            Using Loc_Image As Drawing.Image = Cloc_WebView.Capture(True)
                               Using Loc_Bitmap As New Bitmap(Loc_Image)
                                Using ms As New IO.MemoryStream()
                                  Loc_Bitmap.MakeTransparent(Drawing.Color.White)
                                  Loc_Bitmap.Save(ms, Drawing.Imaging.ImageFormat.Png)
                                  ms.Position = 0
                                  FU_GenerateBase64 = System.Convert.ToBase64String(ms.ToArray)
                                End Using
                              End Using
                            End Using
                          Else                            
                            Loc_TimeOut = True
                          End If
                        End Sub)


looks like the twice rendering that solved a litte bit from the older DLLs doesnt work. Replaced with Thread.Sleep and ThreadRunner it works.

I hope the next release have a way to get rid of the sleeping.
eo_support
Posted: Thursday, July 16, 2015 9:38:47 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
I see. Thank you very much for the update. We will investigate this and see what we can find.

Thanks!
M. Heinsohn
Posted: Tuesday, July 21, 2015 5:37:30 AM
Rank: Member
Groups: Member

Joined: 5/6/2015
Posts: 25
I've tested EO.Total 2015.2.1.2 looks nearly the same. I've reduced the thread.sleep to 25ms without geting wrong images.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.