Solved

About In-Process and Out-Process

Posted on 2001-07-06
9
478 Views
Last Modified: 2013-11-20

Dear exprets ,

Iam working with ActiveX components in visual basic .
The same i raised in VB section also but not yet got any suggessions.
So i posted the same here.
My problem is ,
Iam calling a In-process (Dll) from a client application.
There is big(coded) method in In -process which is executed by client application having reference of this in-process.
Clearly ,The Client is not going to gain the control unless the entire method get executed.
What i decided to do for this, insted calling this big method , if a client call's another method from that in-process component , which host a out-process component and free the client control as soon as out-process is created .
If that out-process component raise an event of this In-process component after some time Interval. We can execute the big processing method without distrubing the client calling this In-Process component.

Experts Please tell me whether is this is possible.
I tried this and got an error as invalid memory reference after it raise the event from In-Process component
Why this error i got.
Hope experts consider this .

regrads
cpearl
0
Comment
Question by:cpearl_s
  • 4
  • 4
9 Comments
 

Author Comment

by:cpearl_s
ID: 6259095
Please experts give me reply ASAP
0
 
LVL 32

Expert Comment

by:jhance
ID: 6259181
I think you are confusing the concepts of in-process and out-of-process COM and multi-threading.  

I think a better solution to your problem is to have the existing ActiveX control do its long running function in a thread rather than go through the overhead of changing from in-proc to out-of-proc.
0
 
LVL 7

Expert Comment

by:peterchen092700
ID: 6259324
jhance is right, changing the location of the server will not alter it's behavior.

Two ways:
a) (as jhance suggested) the client creates a new thread that runs the activex' operation. All Thread Synchronization, Marshaling etc. is  left to the client

b) The ActiveX control creates it's own thread, and offers a function to "start" the operaiton, a functioon to poll the state, and fires an event if the operation is finished.
All threading issues are left to the activeX (I'd prefer this solution for several reasons - but only if you can change the activex)

Note that the Event *must* be fired from the activex control's main thread


Peter
0
 

Author Comment

by:cpearl_s
ID: 6272814
hai jhance and peter,
Yes , i may confused .

Please reconsider this senario.( Actually this is written in VB but I re-structured using C++  )

My In-process (ActiveX Dll)
____________________________________________________
Class Order{
Public:
  LongMethod(){
    <<--- do long process -->>
  }
}
_____________________________________________________

Assume this Class is Created and Deployed as
COM+ Application

Client Application --> Creates a Object Order (COM+)
  set obj = CreateObject("ComPls.Order")

If ClientApplication calls this  LongMethod  
   obj.LongMethod();

Clearly the Client Application won't gain controll back unless and untill that method completes its work.

So , What i thought is, to re-modify the same as.

____________________________________________________
Modified In-process
implement Class Out
Out ObjOut ;
Class Order{
Public:
  StartLongMethod(){
  }
 
  LongMethodCallBack(){
    <<--- do long process -->>
  }
}

 Order::StartLongMethod (){
//Create a Out-Process Component
  set ObjOut=CreateObject("OutProcess")
}
____________________________________________________

As Soon as this is constructed ,a Timer is Executed to make delay automation. After the timer expires this Raise the LongMethodCallBack .(I mean) as soon as out-process is created the client gains the controll back since this is going to be created in seperate thread.
So i designed my Out-Process Component as
____________________________________________________
(ActiveX Exe)
Class Out{
 Out(){
  StartTimer
 }

 TimerCallBack(){
 KillTimer;
 RaiseEvent LongMethodCallBack() ;
 }

 LongMethodCallBack(); // Abstract Method
}
____________________________________________________

When the timer event executed , the outprocess timer destroyes and raise the event LongMethodCallBack of In-Process which executes that longfunctionality.
IF i could able to do this , i can acheive two thing,

1) Client Application is not binded with In-Process untill that long method executes .
2) The Out-Process server the Client Application, from binding .

Please consider and tell what i decided is right or wrong else any other way to do this.

Note : The code is only a Overview on the Logic .Just taket he concept only.

regards
cpearl
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 7

Expert Comment

by:peterchen092700
ID: 6272855
a) You don't need an out-of process server for this
In-Process vs. Out-of-Process is only a question of server location, speed and safety. For almost all things legal in COM it doesn't matter if you have a component running inproc or outproc.

b) I'd suggest (simply because I don't know how to do multithreading in VB) to modify the component to use a separate thread for calculation


class Calculator
{
  HRESULT  StartOperation(); // error if already/still running
  BOOL     IsOperationRunning();
  HRESULT  CancelOperation()

  [outgoing event: operation complete]
  Fire_OperationComplete()
};

StartOperation would create a new thread that calls the lengthy operation.

CancelOperation would best set a flag, that is checkked from time to time in the lengthy op thread. It would then use WaitForSingleObject to wait for the thread to terminate.

When the lengthy operation completes, the thread posts a private Windows message (use RegisterMessage) to the ActiveX control's HWND, and terminates

In the ActiveX controls message handler, you can fire the OperationComplete event.

To take care of:
a) Synchronization beetween the threads
b) the lengthy thread MUST NOT do anything with COM (if it needs, you will need to learn a lot more). not calling COM controls, not firing COM events, etc.


Peter
0
 

Author Comment

by:cpearl_s
ID: 6288373
hai experts ,
many thanks to u and peter.
Peter i got what u tring to say. But the real problem is Visual basic does not support multithreading model, it support only apartment thread model. There my problem started.
Since iam working with VB. That's what i choosen little bit more effort to solve this problem.
Thought iam still in trouble. I did the same logic using..

A Client Application invokes a Out-Process Component in Client System and that is responsible for executing the COM+ (resides in server) object => Client Application is free from Binging with Server Resources(COm+).After it completes the task ,this againg invoke a Event of Caller (  Client Application )which identifies task completed.

But Actuall i thought , this Out-Process should reside inside the server so that instead of ClientAPplication invokes , let COM+ application (DLL's) invoke the same, which reduce the Client System Overheads.

Any how , though i not completely soveld , i patially solved, this with our experts consulting.
Hope i would get more solution iff i dictate the problem in front of some one.
Wishes to u and experts. Thank's to all
regards
cpearl

0
 
LVL 7

Accepted Solution

by:
peterchen092700 earned 100 total points
ID: 6292948
cpearl:
The whole idea was not to expose the worker thread to COM. The COM threading models alny care about how Interfaces are called from different threads.

0
 

Author Comment

by:cpearl_s
ID: 6405202
thank's expert
0
 
LVL 7

Expert Comment

by:peterchen092700
ID: 6405241
why only C? What was missing?
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 82
Expand data scrubbing tool 13 29
Named range not carried over 10 57
changeXy challenge 13 57
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now