Load syntax and document async

SyntaxEditor for Windows Forms Forum

Posted 15 years ago by Steven Liu
Avatar
As my syntax definition gets more complicated, it takes longer to load a document. Currently it takes about 2 - 3 seconds.
This is understandable since SyntaxEditor is doing a lot of processing. Is there a way to load the document in async mode? That way the UI is kept responsive and showing a progress bar, giving better user perception.
I guess I cannot simply launch an async delegate on SyntaxEditor.LoadFile method, since it interacts with UI elemnts.
My suggestion is to split LoadFile into 2 methods: ParseFile and RenderFile. ParseFile reads the file and parse it into internal data structure, RenderFile draws the document text. That way I can call ParseFile with async delegate, then in the callback, call RenderFile on UI thread.
LoadFile will encapsulate ParseFile and RenderFile, and still can be used in sync mode.
This solution is based on the assumption that parsing takes considerably longer than rendering.

Steven Liu

Comments (7)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks for the suggestion... right now async loading is not available however it is something we'd like to do.


Actipro Software Support

Posted 15 years ago by Steven Liu
Avatar
Currently the application window is not refershed while SyntaxEditor is parsing document. As a workaround, is it possible for SyntaxEditor to call Application.DoEvents internally at certain points? The UI still will not be completely responsive but at least the application window may be refreshed.
Steven
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I'm not sure if we can... the problem is that the internal structures would not be in sync if we did that and could possibly throw exceptions or paint the wrong thing in the rendering code.


Actipro Software Support

Posted 12 years ago by Ernesto Obregon
Avatar
Anything new to loading a document asynchronously? Specifically using a Background Worker in vb.net

I am loading log files that are a couple of Megabytes in size that may take several minutes and I would like to update a progress bar on my Windows Form StatusStrip at the bottom of the editor window. Currently the UI is locked while the file is loading. I tried the following code to load the file without updating my progress bar just to see if the file would load first.

BackgroundWorker.RunWorkerAsync()
While Me.BackgroundWorker.IsBusy
     Application.DoEvents()
End While


Private Sub BackgroundWorker_DoWork(ByVal sender as System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker.DoWork
editor.Document.LoadFile(FileInfo.FullName, System.text.Encoding.Default)
End Sub

But I either get a cross thread exception or a Index Out of Range Exception

Thanks
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Ernesto,

Nothing that does it asynchronously but we are open to any suggestions you have that we could possibly add in the future.

You can turn off various stages of parsing though. I believe the documentation has a help topic on large file handling. If you turn off various features of SyntaxEditor you can load huge files almost instantly.


Actipro Software Support

Posted 12 years ago by Ernesto Obregon
Avatar
How about Actipro providing a progress bar control that can be added to the SyntaxEditor?
I think the best solution to doing this after reading many articles and books boils down to updating the progress bar while the file is being loaded one line at a time.

' Similar to a text box being loaded a file one line at a time.
 Do While Not EOF(MyFile.Name)
    readLine = MyFile.Name.ReadLine()
    textboxInput = textboxInput & readLine & vbCrLf
    ProgressBar.Update += 1
 Loop
Since we do not have access to the code (at least I do not think we do) that is behind the LoadFile method in the Document we can not load a file a single line at a time, but does Actipro do something similar to the above code behind the scenes where you could optionally update an Actipro Progressbar ?

Editor.Document.LoadFile(MyFile.Name)
Then we can just enable your progress bar or not.

Thanks

[Modified at 12/04/2007 04:36 PM]
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Unfortunately it isn't designed that way. The issue actually isn't with loading the file itself. As I said, if you turn off parsing, very large files will load almost instantly.

The issue is with the parsing into tokens and semantic data that is taking a while. Right now we don't have a way to asynchronously call back to report the parsing progress however that is something that we will try to add in a future version. I've ensured that it is on the TODO list.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 9 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.