C
Cybertof
Hello,
Is there a good way to call a big time-consumming function from an
ActiveX DLL (interoped) through a thread without blocking the main UI ?
Here are the details :
I have a class CInteropCall encapsulating a call to a visual basic
ActiveX DLL function named FillAlloc_ArrayStruct_Double(), which is
allocating a big struct array an fills it using a inner loop
(for i = 1 to 300000...)
I'm calling this BigProcess through a thread from the main UI
like this :
CInteropCall MyThreadProcess = new CInteropCall();
Thread m_WorkerThread;
m_WorkerThread = new Thread(new ThreadStart(MyThreadProcess.TestMe));
m_WorkerThread.IsBackground = true;
m_WorkerThread.Name = "ThreadLow";
m_WorkerThread.Priority = System.Threading.ThreadPriority.Lowest;
m_WorkerThread.Start();
Here is the TestMe() method from the CInteropCall class which is calling
the function through an instance of a VB6 Class :
public void TestMe()
{
AX_DLL.FillAlloc_ArrayStruct_Double(3000000, ref array_struct_double);
}
The problem is :
The main UI is blocked when starting the thread, and from time to time
during the thread execution.
Solutions tested :
- adding a Sleep(1) in the inner loop of the vb6 function
It does not change a lot
- adding a DoEvents() in the vb6 function
It does not change a lot but slows down the thread execution.
The same big loop executing from a c# function does not block the main
UI (even without sleep(1)...), the UI remains very smooth.
Any idea to make an interoped vb6 activex call 'UI thread friendly' ?
(or maybe there is no way to do it...)
Regards,
Cybertof.
Is there a good way to call a big time-consumming function from an
ActiveX DLL (interoped) through a thread without blocking the main UI ?
Here are the details :
I have a class CInteropCall encapsulating a call to a visual basic
ActiveX DLL function named FillAlloc_ArrayStruct_Double(), which is
allocating a big struct array an fills it using a inner loop
(for i = 1 to 300000...)
I'm calling this BigProcess through a thread from the main UI
like this :
CInteropCall MyThreadProcess = new CInteropCall();
Thread m_WorkerThread;
m_WorkerThread = new Thread(new ThreadStart(MyThreadProcess.TestMe));
m_WorkerThread.IsBackground = true;
m_WorkerThread.Name = "ThreadLow";
m_WorkerThread.Priority = System.Threading.ThreadPriority.Lowest;
m_WorkerThread.Start();
Here is the TestMe() method from the CInteropCall class which is calling
the function through an instance of a VB6 Class :
public void TestMe()
{
AX_DLL.FillAlloc_ArrayStruct_Double(3000000, ref array_struct_double);
}
The problem is :
The main UI is blocked when starting the thread, and from time to time
during the thread execution.
Solutions tested :
- adding a Sleep(1) in the inner loop of the vb6 function
It does not change a lot
- adding a DoEvents() in the vb6 function
It does not change a lot but slows down the thread execution.
The same big loop executing from a c# function does not block the main
UI (even without sleep(1)...), the UI remains very smooth.
Any idea to make an interoped vb6 activex call 'UI thread friendly' ?
(or maybe there is no way to do it...)
Regards,
Cybertof.