472,371 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 software developers and data experts.

async call to ActiveX is still blocking UI

Hello

I am using asynchronous delegates to make a call to a COM ActiveX object, but even though the call occurs on a separate thread, my UI is still blocking.

If i put the thread to sleep in my delegate call, the application is well behaved (no UI freeze), but the call to the com object causes the UI to lock up

Do I have to manage calls to an ActiveX object differently than using the BeginInvoke and a callback

A sample of the code I am using
/// <summary
// Connect to the devic
/// </summary
/// <returns></returns
public bool BeginConnect(

bool bRetVal = false
IAsyncResult ar
int threadId

// Create the delegate
AsyncDelegate dlgt = new AsyncDelegate(m_ad.AutoConnect)

threadId = AppDomain.GetCurrentThreadId()
Console.WriteLine("In BeginConnect Calling BeginInvoke from {0}.", threadId)

// Initiate the asychronous call. Include an AsyncCallbac
// delegate representing the callback method, and the dat
// needed to call EndInvoke
ar = dlgt.BeginInvoke( out threadId, new AsyncCallback(AutoConnectCallback), dlgt )

bRetVal = ar.IsCompleted

return bRetVal

public int AutoConnect(out int threadId)

int ret = 0
Console.WriteLine("Begin Call to: AutoConnect.")

threadId = AppDomain.GetCurrentThreadId()

// ActiveX call that blocks
m_driver.AutoConnect()

Console.WriteLine("End Call to: AutoConnect.")
return ret
Jul 21 '05 #1
1 3222
Using asynch callbacks won't help, probably your activeX object lives on the
UI thread, and the calls are made from the threadpool thread, which is bad
for a number of reasons
- Your set-up requires apartment marshaling - threadpool threads are MTA
while UI thread is STA, and can be a source of numerous threading problems
and perf degradation.
- You will still block the UI while running activeX methods.

What you should do instead of using asynch delegates is create a separate
thread initialized for STA, create an instance of your activeX object and
call his methods on that same thread. Note that if you need to access the UI
thread from this thread, you need to call Control.Invoke or
Control.BeginInvoke.

Willy.
"Marwan" <an*******@discussions.microsoft.com> wrote in message
news:C1**********************************@microsof t.com...
Hello,

I am using asynchronous delegates to make a call to a COM ActiveX object,
but even though the call occurs on a separate thread, my UI is still
blocking.

If i put the thread to sleep in my delegate call, the application is well
behaved (no UI freeze), but the call to the com object causes the UI to
lock up.

Do I have to manage calls to an ActiveX object differently than using the
BeginInvoke and a callback?

A sample of the code I am using:
/// <summary>
// Connect to the device
/// </summary>
/// <returns></returns>
public bool BeginConnect()
{
bool bRetVal = false;
IAsyncResult ar;
int threadId;

// Create the delegate.
AsyncDelegate dlgt = new AsyncDelegate(m_ad.AutoConnect);

threadId = AppDomain.GetCurrentThreadId();
Console.WriteLine("In BeginConnect Calling BeginInvoke from {0}.",
threadId);

// Initiate the asychronous call. Include an AsyncCallback
// delegate representing the callback method, and the data
// needed to call EndInvoke.
ar = dlgt.BeginInvoke( out threadId, new
AsyncCallback(AutoConnectCallback), dlgt );

bRetVal = ar.IsCompleted;

return bRetVal;
}

public int AutoConnect(out int threadId)
{
int ret = 0;
Console.WriteLine("Begin Call to: AutoConnect.");

threadId = AppDomain.GetCurrentThreadId();

// ActiveX call that blocks!
m_driver.AutoConnect();

Console.WriteLine("End Call to: AutoConnect.");
return ret;
}

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Vanessa | last post by:
I have a question regarding async mode for calling Microsoft.XMLHTTP object. Microsoft.XMLHTTP hangs the IE once in a while suddenly, but it will work again after half an hour or so without doing...
2
by: Tom Vandeplas | last post by:
Hi all, When using an asynchronous API call (in my case WriteFileEx) in a thread it seems to become blocking instead of non-blocking (see details below). Can somebody explain me what is...
11
by: ryan | last post by:
Hi, I've omitted a large chunk of the code for clarity but the loop below is how I'm calling a delegate function asynchronously. After I start the each call I'm incrementing a counter and then...
1
by: Marwan | last post by:
Hello I am using asynchronous delegates to make a call to a COM ActiveX object, but even though the call occurs on a separate thread, my UI is still blocking. If i put the thread to sleep in my...
10
by: Brian Parker | last post by:
I inherited a C++ DLL that I need to remotely call multiple times asynchronously. What I have developed is: CSharp web application that makes asynchronous calls to a CSharp Web Service. The...
6
by: Shak | last post by:
Hi all, Three questions really: 1) The async call to the networkstream's endread() (or even endxxx() in general) blocks. Async calls are made on the threadpool - aren't we advised not to...
11
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling...
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
10
by: ColoradoGeiger | last post by:
I have a fairly standard server application that I am using asynchronous socket calls to make connections, send and receive data, and all of that jazz. No blocking methods was my goal in writing...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.