DLL with an infinite loop? 
Author Message
 DLL with an infinite loop?

I need to have a DLL running on it's own process. My app will call the dll
and get it going then almost ignore it untill the app closes down. When
closing down the app will terminate the dll.
What I'm trying to do is to make sure what ever app is passed to it will
stay running.

What I would like to do is this:

1. App calls/starts dll on it's own process and passes app path to it (eg.
"C:\test.exe")
2. Dll will take the info, and start an infinite loop ( I want to have as
little down time as possible, so it needs to regonize that test.exe is not
running as soon as possible) checking to see if test.exe is still
running. --- I know how to do that
3. Dll will inform app that dll has successfully completed it's initializing
and it is running. (via a return code)
4. App will go about it's task.
5. Authorized user closes down app.. in the process, it closes down dll.
    5.A. Could I call an other function that would stop the loop then close
down the dll, or just kill/abort it? (the latter I know how to do.)

I'm writting both the app and the dll.
Is this possible?

Thanks, Seth



Sun, 05 Jun 2005 13:20:29 GMT  
 DLL with an infinite loop?
On Wed, 18 Dec 2002 00:20:29 -0500, "Seth Bembeneck"

Quote:

>I need to have a DLL running on it's own process. My app will call the dll
>and get it going then almost ignore it untill the app closes down. When
>closing down the app will terminate the dll.
>What I'm trying to do is to make sure what ever app is passed to it will
>stay running.

I think you've basically got the concept, but I'll clarify things a
little - it'll help you with the design & implementation.

Quote:

>What I would like to do is this:

>1. App calls/starts dll on it's own process and passes app path to it (eg.
>"C:\test.exe")

1. The application loads the DLL. The DLL gets the name of the
application.

Quote:
>2. Dll will take the info, and start an infinite loop ( I want to have as
>little down time as possible, so it needs to regonize that test.exe is not
>running as soon as possible) checking to see if test.exe is still
>running. --- I know how to do that

2. In the DLL start routine, create a new thread ("infinite loop").
Once thread is created, start it, then return from the DLL. The
"downtime" is determined by the speed at which the thread is created.
Usually neglible.

Quote:
>3. Dll will inform app that dll has successfully completed it's initializing
>and it is running. (via a return code)

3. DLL should post a message, or signal the application in some other
way - not by returning a return code from the start-up routine.

Quote:
>4. App will go about it's task.

4. As you've stated. And DLL thread goes about its task.

Quote:
>5. Authorized user closes down app.. in the process, it closes down dll.

5. App closes causing a DLL unload event

Quote:
>    5.A. Could I call an other function that would stop the loop then close
>down the dll, or just kill/abort it? (the latter I know how to do.)

6. In DLL unload event handler, stop the thread. Best to do this by
sending a user-defined message to the thread to request that it stops
doing whatever it's doing. Implementing a time-out is a good idea.

Quote:

>I'm writting both the app and the dll.

You didn't mention if the DLL is going to be written in VB or not, so
I kept things as generic as possible.


Sun, 05 Jun 2005 20:18:52 GMT  
 DLL with an infinite loop?
Yes, both the app and the DLL will be written in VB.

In step 3, how would I post a message?
And in step 6 how would I send the message to the thread?

Thanks,
Seth


Quote:
> On Wed, 18 Dec 2002 00:20:29 -0500, "Seth Bembeneck"

> >I need to have a DLL running on it's own process. My app will call the
dll
> >and get it going then almost ignore it untill the app closes down. When
> >closing down the app will terminate the dll.
> >What I'm trying to do is to make sure what ever app is passed to it will
> >stay running.

> I think you've basically got the concept, but I'll clarify things a
> little - it'll help you with the design & implementation.

> >What I would like to do is this:

> >1. App calls/starts dll on it's own process and passes app path to it
(eg.
> >"C:\test.exe")

> 1. The application loads the DLL. The DLL gets the name of the
> application.

> >2. Dll will take the info, and start an infinite loop ( I want to have as
> >little down time as possible, so it needs to regonize that test.exe is
not
> >running as soon as possible) checking to see if test.exe is still
> >running. --- I know how to do that

> 2. In the DLL start routine, create a new thread ("infinite loop").
> Once thread is created, start it, then return from the DLL. The
> "downtime" is determined by the speed at which the thread is created.
> Usually neglible.

> >3. Dll will inform app that dll has successfully completed it's
initializing
> >and it is running. (via a return code)

> 3. DLL should post a message, or signal the application in some other
> way - not by returning a return code from the start-up routine.

> >4. App will go about it's task.

> 4. As you've stated. And DLL thread goes about its task.

> >5. Authorized user closes down app.. in the process, it closes down dll.

> 5. App closes causing a DLL unload event

> >    5.A. Could I call an other function that would stop the loop then
close
> >down the dll, or just kill/abort it? (the latter I know how to do.)

> 6. In DLL unload event handler, stop the thread. Best to do this by
> sending a user-defined message to the thread to request that it stops
> doing whatever it's doing. Implementing a time-out is a good idea.

> >I'm writting both the app and the dll.

> You didn't mention if the DLL is going to be written in VB or not, so
> I kept things as generic as possible.



Sun, 05 Jun 2005 21:23:08 GMT  
 DLL with an infinite loop?
On Wed, 18 Dec 2002 08:23:08 -0500, "Seth Bembeneck"

Quote:

>Yes, both the app and the DLL will be written in VB.

>In step 3, how would I post a message?
>And in step 6 how would I send the message to the thread?

You might want to use the MessageQueue object. However, if you're sure
you're only going to have a single instance of a DLL, a shared method
accessing a shared object representing a signal is good enough. It
depends on how many instances you have, remoting etc., or even how
complex your message needs to be (in this case, I suspect it doesn't
need to be complicated at all).

e.g.

This demonstrates the request-to-stop functionality. The RequestStop()
is called by the application, while the ReceivedStopRequest() is
called as often as possible in your loop.

Public Class MyDLL
        ...

        Public Sub New()
                m_StopRequested = False
        End Sub

        Public Shared Sub RequestStop()
                m_StopRequest = True
        End Sub

        Protected Function ReceivedStopRequest() As Boolean
                Return m_StopRequested
        End Function

        Private Shared m_StopRequest As Boolean

End Class

An additional piece of useful functionality, wait-for-stop, can be
added to the class. I've implemented a simple loop example.

Public Class MyDLL

        Public Sub New()
                ...
                m_StopRequested = False
                m_Stopped = False
                ' Now create the thread to run RunDLL()
                ...
        End Sub

        Public Sub Dispose()
                ...
                WaitForStop()
                ' Destroy the thread object
                ...
        End Sub

        Public Shared Sub RequestStop()
                m_StopRequest = True
        End Sub

        Public Shared Sub WaitForStop()
                RequestStop()
                While m_Stopped = False
                        ' Sleep, or DoEvents, or timeout
                Wend
        End Sub

        Protected Sub SetStopped()
                m_Stopped = True
        End Sub

        Protected Function ReceivedStopRequest() As Boolean
                Return m_StopRequested
        End Function

        ' This method would be running in a separate thread
        ' and would probably exist in a separate class.

        Protected Sub RunDLL()
                While Not ReceivedStopRequest()
                        Debug.WriteLine("Running")
                Wend
                SetStopped()
        End Sub

        Private Shared m_StopRequest As Boolean
        Private Shared m_Stopped As Boolean
End Class



Sun, 05 Jun 2005 22:03:39 GMT  
 DLL with an infinite loop?
Is it possible for the DLL to raise an event that my App could catch? Or
some other way that the App can find out if the DLL has been shut down?

Thanks for you help,

Seth


Quote:
> On Wed, 18 Dec 2002 08:23:08 -0500, "Seth Bembeneck"

> >Yes, both the app and the DLL will be written in VB.

> >In step 3, how would I post a message?
> >And in step 6 how would I send the message to the thread?

> You might want to use the MessageQueue object. However, if you're sure
> you're only going to have a single instance of a DLL, a shared method
> accessing a shared object representing a signal is good enough. It
> depends on how many instances you have, remoting etc., or even how
> complex your message needs to be (in this case, I suspect it doesn't
> need to be complicated at all).

> e.g.

> This demonstrates the request-to-stop functionality. The RequestStop()
> is called by the application, while the ReceivedStopRequest() is
> called as often as possible in your loop.

> Public Class MyDLL
> ...

> Public Sub New()
> m_StopRequested = False
> End Sub

> Public Shared Sub RequestStop()
> m_StopRequest = True
> End Sub

> Protected Function ReceivedStopRequest() As Boolean
> Return m_StopRequested
> End Function

> Private Shared m_StopRequest As Boolean

> End Class

> An additional piece of useful functionality, wait-for-stop, can be
> added to the class. I've implemented a simple loop example.

> Public Class MyDLL

> Public Sub New()
> ...
> m_StopRequested = False
> m_Stopped = False
> ' Now create the thread to run RunDLL()
> ...
> End Sub

> Public Sub Dispose()
> ...
> WaitForStop()
> ' Destroy the thread object
> ...
> End Sub

> Public Shared Sub RequestStop()
> m_StopRequest = True
> End Sub

> Public Shared Sub WaitForStop()
> RequestStop()
> While m_Stopped = False
> ' Sleep, or DoEvents, or timeout
> Wend
> End Sub

> Protected Sub SetStopped()
> m_Stopped = True
> End Sub

> Protected Function ReceivedStopRequest() As Boolean
> Return m_StopRequested
> End Function

> ' This method would be running in a separate thread
> ' and would probably exist in a separate class.

> Protected Sub RunDLL()
> While Not ReceivedStopRequest()
> Debug.WriteLine("Running")
> Wend
> SetStopped()
> End Sub

> Private Shared m_StopRequest As Boolean
> Private Shared m_Stopped As Boolean
> End Class



Mon, 06 Jun 2005 10:46:52 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. EOF Problem, Infinite Loop

2. infinite loop

3. Suggestion for tracking down infinite loop on release only

4. Infinite Loop when compiling under Visual Studio VB .NET

5. Infinite loop in compile, especially in abstract classes

6. VB5 setup wizard problem. Infinite user loop

7. Infinite loops

8. An infinite loop question ?

9. Infinite Loop

10. Infinite loop in Word97/VBA

11. break key in infinite loop

12. Infinite pause in loop

 

 
Powered by phpBB® Forum Software