Question about making Asynchronous call in C# (WPF) to COM object

Posted by Andrew on Stack Overflow See other posts from Stack Overflow or by Andrew
Published on 2010-06-03T18:43:30Z Indexed on 2010/06/03 19:24 UTC
Read the original article Hit count: 286

Filed under:
|
|

Hi,

Sorry to ask such a basic question but I seem to have a brain freeze on this one! I'm calling a COM (ATL) object from my WPF project. The COM method might take a long time to complete. I thought I'd try and call it asychronously. I have a few demo lines that show the problem.

private void checkBox1_Checked(object sender, RoutedEventArgs e)
 {
      //DoSomeWork();
      AsyncDoWork caller = new AsyncDoWork(DoSomeWork);
      IAsyncResult result = caller.BeginInvoke(null, null);            
  }

private delegate void AsyncDoWork();
private void DoSomeWork()
{
   _Server.DoWork();
}

The ATL method DoWork is very exciting. It is:

STDMETHODIMP CSimpleObject::DoWork(void)
{

Sleep(5000); return S_OK; }

I had expectations that running this way would result in the checkbox being checked right away (instead of in 5 seconds) and me being able to move the WPF gui around the screen. I can't - for 5 seconds.

What am I doing wrong? I'm sure it's something pretty simple. Delegate signature wrong?

Thanks.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about com-interop