1

I am using COM-automation to write-out data to an already-open Word-document.

As this operation takes quite sometime I'd like to show a progressbar to the user.

It is not possible to do the data-writeout in a backgroundworker, because this will cause the Word-application to throw exception rpc_e_servercall_retrylater even with MessageFilter implemented. I've learned this is due to Words foreground thread has trouble communicating with background thread.

Is it possible to turn it the other way around and instead use a new thread to display the progressbar? I've tried to open a new winform with only the progressbar inside it, and open it on it's own thread, but it is not updating.

Other ideas?

sebb3
  • 11
  • 2
  • Can you use Invoke from the background worker thread to have the work dispatched and run on the main UI thread? – mclaassen Jul 09 '14 at 16:50
  • if i'm not wrong backgroundworker expose progress event in there you may update your progress bar.WinForm are STA and when you are using another thread there's issue to comunicate and you may face cross thread exception...coz control stay into a trhead background worker process data into another. – makemoney2010 Jul 09 '14 at 19:17
  • i have done something few month ago let me check so i can post you some detailed infos. – makemoney2010 Jul 09 '14 at 19:18

1 Answers1

0

here a little snippet that i hope could help you

 private void BackgroundWorker2_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
   string S = Convert.ToString(e.UserState);
   Label1.Text = S;
   ProgressBar1.PerformStep();
   S = null;
}




 Private Sub BackgroundWorker2_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BackgroundWorker2.ProgressChanged
    Dim S As String = CType(e.UserState, String)
    Label1.Text = S
    ProgressBar1.PerformStep()
    S = Nothing
End Sub
makemoney2010
  • 1,222
  • 10
  • 11