Problem with SemanticParserService

SyntaxEditor for Windows Forms Forum

Posted 17 years ago by Tim Winquist - CTO, Analysis, Integration & Design, Inc.
Version: 4.0.0251
Avatar
I have a List of SyntaxEditor objects. Each object's Document has the same Language assigned to it and all Documents' text is valid. The SemanticParserService is automatically invoked and parsing takes less than a second for all Documents. That is all a-ok.

Problem: I have a button in my application that, when pressed, makes a copy of all current SyntaxEditor objects (the code is below). When the SyntaxEditors' Document.Text members are assigned, the SemanticParserService is invoked (I verified this in debug). Parsing bogs down and MyDynamicSyntaxLanguage.PerformSemanticParse(...) never returns a CompilationUnit object. I can see that the first Document is being parsed and the SemanticParserServiceRequests are pending for all the other SyntaxEditors' Documents. The CPU Usage in Windows Task Manager is buried at 100%.

What in the world is causing this? Here is the code:

List<SyntaxEditor> aSyntaxEditorCopies = new List<SyntaxEditor>();
foreach (SyntaxEditor oSyntaxEditorOriginal in this.aSyntaxEditorOriginals)
{
  SyntaxEditor oSyntaxEditorCopy = new SyntaxEditor();
  string strFileContents = oSyntaxEditorOriginal.Document.Text;
  oSyntaxEditorCopy.Document.Text = strFileContents;
  oSyntaxEditorCopy.Document.Language = this.oDSLanguage;
  aSyntaxEditorCopies.Add(oSyntaxEditorCopy);

  // Monitor the IsBusy flag.
  //   Without it, all CompilationUnits remain null and program crashes
  while (SemanticParserService.IsBusy == true) { }
}

Comments (5)

Posted 17 years ago by Tim Winquist - CTO, Analysis, Integration & Design, Inc.
Avatar
I just noticed something very interesting. If I insert the line "MessageBox.Show("foo");" just before the 'while' loop, everything seems to work fine (i.e. the semantic parser completes all requests). Obviously this is not a solution but I just thought it was interesting. Does this help diagnosis the problem?
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I think your while loop causes a deadlock since the callback from the worker thread in the semantic parser service does hit the main UI thread upon completion. In this case your loop is probably preventing it from executing.

Instead of this, if you require that all of the parsing ops be completed sequentially, simply Stop the service. This will kill the worker thread and run in the main UI thread. Then Start it again when you want to have threaded parsing again.


Actipro Software Support

Posted 17 years ago by Tim Winquist - CTO, Analysis, Integration & Design, Inc.
Avatar
That just seems like a workaround to me. It really seems like the SemanticParserService should return without a call to something like MessageBox after Document.Text is assigned a value. I would think that you could wait until the SemanticParserService has processed all requests. I tried WaitForParse(...), I tried monitoring the IsBusy property among other things. It isn't working that way. Is Stopping and reStarting the service the RIGHT way to do this? If it is, then I will use that as the solution.

Thanks again
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Tim,

Stopping the SemanticParserService just causes all semantic parsing to be run in the main UI thread instead of a worker thread. So this may accomplish what you want.

However the more elegant way of doing things would be to load all your documents and then call WaitForParse by passing in the parse hash key of the last document that was loaded. This theoretically would block the main thread until the last document's semantic parsing was complete. However when testing this, there appears to be a bug in WaitForParse. We've spent much of this afternoon working on a fix and if you'd like to help us test it, please send our support address an email and we'll get you hooked up with a preview build to try.


Actipro Software Support

Posted 17 years ago by Tim Winquist - CTO, Analysis, Integration & Design, Inc.
Avatar
Yes. I tried using WaitForParse(...) and it definitely didn't work. I will send an email to support. Thanks again.
The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.