5 Replies - 900 Views - Last Post: 07 September 2009 - 10:37 PM Rate Topic: -----

#1 mycraz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 81
  • Joined: 10-June 09

multithreads

Posted 07 September 2009 - 12:08 AM

hi,
i am working on an experiment whether a thread can terminate another thread while it is sleeping or not. The problem is
1) Can I do this without using activex.exe or is there any other way to do it without creating multithreads or must i use multithreads?
2) I tried to use activex.exe to create objects it always said that activex component can't create object :error 249. I had register activex and it still pop up this error. How can I solve it?
3) When I tried to use activex.exe to do a simple application for displaying threadID, when i compile and run it, there's no form coming out or any actions. What is the problem?

Is This A Good Question/Topic? 0
  • +

Replies To: multithreads

#2 danny_kay1710  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 28
  • View blog
  • Posts: 358
  • Joined: 27-April 08

Re: multithreads

Posted 07 September 2009 - 01:09 AM

As far as I am aware you cannot do multi-threading in VB6.

If you want to test if a thread can terminate another sleeping thread then yes you must do multithreading.

What do you mean by activex.exe. VB6 allows you to create ActiveX objects but I cannot see how this is relevant to what you want. An ActiveX object will generally not have a form at all so you wouldn't see an output.

You should create a Standard EXE although like I said before I don't think VB6 can multithread. I think there are ways to make it act like it is working on things at the same time, I am not sure it is actually multithreading as it would be regarded in other languages.
Was This Post Helpful? 0
  • +
  • -

#3 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: multithreads

Posted 07 September 2009 - 04:46 AM

For a very simple example on multi-threading see strongm's post in this thread...


http://www.tek-tips....d=519374&page=1



Good Luck
Was This Post Helpful? 0
  • +
  • -

#4 Billgoates  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-July 09

Re: multithreads

Posted 07 September 2009 - 04:50 AM

View Postmycraz, on 6 Sep, 2009 - 11:08 PM, said:

hi,
i am working on an experiment whether a thread can terminate another thread while it is sleeping or not. The problem is
1) Can I do this without using activex.exe or is there any other way to do it without creating multithreads or must i use multithreads?
2) I tried to use activex.exe to create objects it always said that activex component can't create object :error 249. I had register activex and it still pop up this error. How can I solve it?
3) When I tried to use activex.exe to do a simple application for displaying threadID, when i compile and run it, there's no form coming out or any actions. What is the problem?


The VB6 way of multithreading is by using ActiveX executables. But it is not as straightforward as it should be.

An ActiveX exe is like a normal exe, but can be accessed as if it's a vb6.dll (ole automation). From the client you have to call set newobject = createobjext("activexexename.classname") to start a class in the activex. The newly created object can now be called as if it's a regular object, but it runs in another process.

One major drawback of this method is that the client is blocked during calls to the activex.exe. The client isn't multithreaded and waits for the call to return. The trick is to start a (hidden) form with a timer in the activex.exe so the call will immediately return to the client. The timer can start a loop, or is the thread. Instead of a timer, you could use the settimer api call.

Personally I don't like this way and to be honest, it's not real multithreading.

Real multithreading can be done in VB6, but uses some advanced methods. In short, the problem with CreateThread in VB6 is that the runtime library isn't initialized. So any call using VBA methods will result in a crash. The only calls allowed are keywords and api calls declared in type libraries. Also it's not possible to debug WinApi threads in the IDE.

If you really want to know how to do it, I only can point you in the direction where to search. Matthew Curland - Advanced Visual Basic 6: Power Techniques for Everyday Programs.

This post has been edited by Billgoates: 07 September 2009 - 05:11 AM

Was This Post Helpful? 0
  • +
  • -

#5 Billgoates  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-July 09

Re: multithreads

Posted 07 September 2009 - 05:09 AM

View Postvb5prgrmr, on 7 Sep, 2009 - 03:46 AM, said:

For a very simple example on multi-threading see strongm's post in this thread...


http://www.tek-tips....d=519374&page=1



Good Luck


That approach works in VB5 but will crash VB6 when you put actual code in the threads.
Was This Post Helpful? 0
  • +
  • -

#6 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: multithreads

Posted 07 September 2009 - 10:37 PM

No it won't, in fact it will run in the IDE but of course you cannot debug it. I have used something similar to the example to manipulate a database but the thing that I made sure of is that each thread had all its own objects. Meaning no references to any variables or other objects outside of the code being run (which is where many will fail).


Good Luck
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1