[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ms-dcom
Subject:    Help Required....
From:       Rajesh G <G.Rajesh () BLR ! SPCNL ! CO ! IN>
Date:       2001-07-30 13:55:01
[Download RAW message or body]


Hi,

I have an COM Server which is an EXE. I have a client which launches
multiple threads. From each thread, I want to call CoCreateInstance of the
Component. In one of the functions of the Interface, I have a function which
takes some time to execute. I don't want the other threads to be blocked
because of the one of thread. How to come over this problem. Any Suggestions
Please...

Thanks in Advance,

Rajesh G.

The Sample Code. This is similar to what I require.

//Component
STDMETHODIMP CApartComp::GetData(int nIndex)
{
        if(nIndex < 4)
        {
                for(int i(0); i < 10000000000; i++);
        }
        ::MessageBox(NULL,"Both Component","Component",MB_OK);
        return S_OK;
}

//Client Code

UINT ThreadProc(LPVOID pVoid)
{
        int* pIndex = (int*) pVoid;
        TRACE("Index Number in Thread is %d\n", *pIndex);
        CoInitialize(NULL);
        IApartInterface* pIntr;
        HRESULT hRes = CoCreateInstance(CLSID_ApartComp,NULL,

CLSCTX_ALL,IID_IApartInterface,(void**)&pIntr);
        if(FAILED(hRes))
        {
                AfxMessageBox("Error Creating Component");
                return 1;
        }
        pIntr->GetData(*pIndex);
        return 0;
}

void CMainFrame::OnGetdata()
{
        for(int i(0); i < 5; i++)
        {
                int nIndex = i+1;
                TRACE("Index from mainframe is %d\n", nIndex);
                CWinThread* pThread = AfxBeginThread(ThreadProc,(void*)
&nIndex,THREAD_PRIORITY_NORMAL,CREATE_SUSPENDED);
                ResumeThread(pThread->m_hThread);
        }

}

----------------------------------------------------------------
Users Guide http://discuss.microsoft.com/archives/mailfaq.asp
contains important info. Save time, search the archives at
http://discuss.microsoft.com/archives/index.html .
To unsubscribe, mailto:DCOM-signoff-request@DISCUSS.MICROSOFT.COM

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic