We're sorry GroupDocs doesn't work properply without JavaScript enabled.

Free Support Forum - groupdocs.com

Error Running GroupDocs.Viewer.Winforms Sample App

I’m attempting to run the sample winforms application I downloaded with the evaluation version of GroupDocs.Viewer.

After specifying a document to load, the following error occurs: “System.InvalidOperationException: cross-thread operation not valid: Control ‘MainForm’ accessed from a thread other than the thread it was created on.”

This occurs in the DisplayViewInfo() method, on SetFormTitle(“No document loaded.”). If that is commented out, it occurs on subsequent references to the form.

Any assistance welcomed and appreciated!

Hi @stevenbras

I can add the InvokeRequired check, but I can’t reproduce the issue locally.
Might you attach your document on that issue occurs?
What is your OS?

Hello,

This error occurs no matter what document I choose; Word doc, Excel file, text file, pdf.

I’m running windows 10.0.19044.1348; Visual Studio 2019, latest patch. Let me know if I can provide any more details. Thanks!

Hi @stevenbras

I can reproduce your issue only I enable cross-check explicitly:
MainForm.CheckForIllegalCrossThreadCalls = true;

I will provide additional fix and reply on this topic.

Hi @stevenbras

I have added an additional cross-thread check, please pull from to repository.

For cross-thread check in your Windows Forms you can use the following code pattern:

public void InvokeIfRequired(MethodInvoker action)
{
      if (this.InvokeRequired)
      {
           this.Invoke(action);
      }
      else
      {
           action();
      }
}

And wrap code inside thread, that might cause “cross-thread operation issue” with lambda function:

InvokeIfRequired(() =>
{
    openFileBtn.Enabled = true;
});

Thank you for resolving this!

@stevenbras

You are welcome!