473,769 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application.DoE vents in a module?

Hi,

Is there an equivalent to the "Application.Do events" method in modules or
Windows services?

I want to make a Windows service that calls a DLL. The DLL would have all my
functions and it would be doing all the job, but some of the functions that
I'm using require calling something like "Application.Do events" and I can't
use this because the DLL module is not an application.

Is there a workaround?
Dec 8 '05 #1
13 10104
A windows service doesn't have user events like a windows form would - so
what could it process?

Perhaps you can pass a flag into your function to let it know whether it
should call application.doe vents or not. Windows application can pass it in
as true, and it will get called, all other applications will pass in false.

"Amjad" <Am***@discussi ons.microsoft.c om> wrote in message
news:61******** *************** ***********@mic rosoft.com...
Hi,

Is there an equivalent to the "Application.Do events" method in modules or
Windows services?

I want to make a Windows service that calls a DLL. The DLL would have all
my
functions and it would be doing all the job, but some of the functions
that
I'm using require calling something like "Application.Do events" and I
can't
use this because the DLL module is not an application.

Is there a workaround?

Dec 8 '05 #2
Marina,

I didn't mention "user events". My DLL module raises other events. All my
functions are in the DLL module, so I cannot run Application.Doe vents in any
of my functions.

I want to process all Windows messages currently in the message queue from
within my DLL module. I know how to do it in a WindowsForm (using
Application.Doe vents), but I don't know how to do it in a module form.

"Marina" wrote:
A windows service doesn't have user events like a windows form would - so
what could it process?

Perhaps you can pass a flag into your function to let it know whether it
should call application.doe vents or not. Windows application can pass it in
as true, and it will get called, all other applications will pass in false.

"Amjad" <Am***@discussi ons.microsoft.c om> wrote in message
news:61******** *************** ***********@mic rosoft.com...
Hi,

Is there an equivalent to the "Application.Do events" method in modules or
Windows services?

I want to make a Windows service that calls a DLL. The DLL would have all
my
functions and it would be doing all the job, but some of the functions
that
I'm using require calling something like "Application.Do events" and I
can't
use this because the DLL module is not an application.

Is there a workaround?


Dec 8 '05 #3
The point is that you are calling the methods in the dll from a windows
service therfore there is no window and, ergo, there is no window message
queue, so there is no pint in calling Application.Doe vents.

If you are looking to relinquish the remainder of the time slice for the
current thread so that other threads can 'get a look in' then you need to
have a look at Thread.Sleep.

"Amjad" <Am***@discussi ons.microsoft.c om> wrote in message
news:FD******** *************** ***********@mic rosoft.com...
Marina,

I didn't mention "user events". My DLL module raises other events. All my
functions are in the DLL module, so I cannot run Application.Doe vents in
any
of my functions.

I want to process all Windows messages currently in the message queue from
within my DLL module. I know how to do it in a WindowsForm (using
Application.Doe vents), but I don't know how to do it in a module form.

"Marina" wrote:
A windows service doesn't have user events like a windows form would - so
what could it process?

Perhaps you can pass a flag into your function to let it know whether it
should call application.doe vents or not. Windows application can pass it
in
as true, and it will get called, all other applications will pass in
false.

"Amjad" <Am***@discussi ons.microsoft.c om> wrote in message
news:61******** *************** ***********@mic rosoft.com...
> Hi,
>
> Is there an equivalent to the "Application.Do events" method in modules
> or
> Windows services?
>
> I want to make a Windows service that calls a DLL. The DLL would have
> all
> my
> functions and it would be doing all the job, but some of the functions
> that
> I'm using require calling something like "Application.Do events" and I
> can't
> use this because the DLL module is not an application.
>
> Is there a workaround?


Dec 8 '05 #4
Amjad,

In addition to the others.

On what event it will than have to react?

Cor
Dec 9 '05 #5
I want to communicate with an RS232 COM port, so I transmit a command to the
port and listen for replies in a threaded infinite loop. In my WindowsForm
application I used the "Application.Do events" after sending the command in
the loop. I also used it in another function after calling a Dial-up
"Connect" method.

It seemed to me that the "Doevents" method was important to force Microsoft
Windows (and not necessarily the WindowsForm) to process any messages
generated by my application now.

I'm concluding from your replies that a DLL module cannot generate Windows
Messages.
"Cor Ligthert [MVP]" wrote:
Amjad,

In addition to the others.

On what event it will than have to react?

Cor

Dec 9 '05 #6
Amjad,

Not my part of sport however have a look at Dick Griers his pages.

http://www.hardandsoftware.net/

I hope this helps,

Cor
Dec 9 '05 #7
"Amjad" <Am***@discussi ons.microsoft.c om> schrieb
I want to communicate with an RS232 COM port, so I transmit a
command to the port and listen for replies in a threaded infinite
loop. In my WindowsForm application I used the
"Application.Do events" after sending the command in the loop. I also
used it in another function after calling a Dial-up "Connect"
method.

It seemed to me that the "Doevents" method was important to force
Microsoft Windows (and not necessarily the WindowsForm) to process
any messages generated by my application now.

I'm concluding from your replies that a DLL module cannot generate
Windows Messages.


It doesn't matter if the code is an a module or in a (not-module) class.
Whether you can use DoEvents or not - like the others have already said -
depends on the fact whether the code is running in a UI (user interface)
thread. A UI thread is a thread that has a message queue. A thread gets a
message queue if you create a window (AKA Control, Form) in the thread. The
message loop is there to process all the messages and it runs all the time
to wait for the messages. In .Net, the message loop is contained in
Application.Run . If you write your own sub main, you have to call
Application.Run to keep the thread/app alife. If you specify a Form as the
startup object, VB.Net internally creates a sub main that only contains
"application.ru n(new Startupform)".

'DoEvents' is a kind of 'workaround' if you are running in a loop where the
thread's main task is doing a job while still being able to process the
messges in the message queue. DoEvents also processes theses messages.
Usually, the job that I mentioned should then be pushed to a different
thread so that the main thread, which is the UI thread, can keep on
processing messages while the other thread is doing it's job without the
need for DoEvents.

In a service, there is no UI. Thus, you don't have a message loop. Long
story short: The question is whether you would need a message loop to get
the events from your COM port. If possible, do the following:

1. make a test application (WindowsApplica tion!)
2. Write an event handler for the event that you need to handle
3. set a breakpoint in the event handler
4. run
5. Post the full callstack here

Depending on the component you are using, it might be possible that it does
*not* depend on windows messages because some components offer a callback
mechanism instead. If this is there, use it. Otherwise, and if a message
loop is not allowed in a service (I am not a service expert), you can not
use the component in the service.
Armin

Dec 9 '05 #8
Hi Amjad

What method/component are you using to communicate with the coms port? Have
you written it yourself or is a third-party (or MS in VS2005) component?

If it is a third-party component then I would imagine there would be an
event raised when data is received. If you have written it yourself then you
probably want to emulate this behaviour.

My guess is that you send data on the DLL's main thread, and data is
received on a worker thread. Therefore, having sent the data, you want to
sit and wait for a response, like this

<snip>
Public Class MyDLL
Private WithEvents m_Port as RS232
Private m_DeviceAttache d As Boolean = False

Public Sub New(ByVal portNumber as Integer)
m_Port = New RS232(portNumbe r)
End Sub

Public Function IsDeviceAttache d() As Boolean

Dim TimeOut As Integer = 300 ' timeout of 3 seconds

m_Port.Send(... )

Do While Not m_DeviceAttache d And TimeOut > 0
' DoEvents not available here
Thread.Sleep(10 )

TimeOut -= 1
Loop

Return m_DeviceAttache d

End Function

Private Sub DataReceived(By Val sender As Object, ByVal e As
ComEventArgs) _
Handles m_Port.DataRece ived

' Look at data to decide whether device is attached and return
result
' ...

m_DeviceAttache d = True

End Sub

End Class
</snip>

Of course, DoEvents is not available to you, as you have discovered, so use
Sleep() instead.

This is a quick-and-dirty way of doing it. Personally, I use a Monitor and
block the main thread until data is received or a timeout occurs, but the
logic is basically the same.

HTH

Charles
"Amjad" <Am***@discussi ons.microsoft.c om> wrote in message
news:6C******** *************** ***********@mic rosoft.com...
I want to communicate with an RS232 COM port, so I transmit a command to
the
port and listen for replies in a threaded infinite loop. In my WindowsForm
application I used the "Application.Do events" after sending the command in
the loop. I also used it in another function after calling a Dial-up
"Connect" method.

It seemed to me that the "Doevents" method was important to force
Microsoft
Windows (and not necessarily the WindowsForm) to process any messages
generated by my application now.

I'm concluding from your replies that a DLL module cannot generate Windows
Messages.
"Cor Ligthert [MVP]" wrote:
Amjad,

In addition to the others.

On what event it will than have to react?

Cor

Dec 9 '05 #9
"Charles Law" <bl***@nowhere. com> schrieb

Of course, DoEvents is not available to you, as you have discovered,
so use Sleep() instead.


If the event of the component he is using is solely based on windows
messages - wrapped in an event - Sleep is no replacment and does not help
here.
Armin

Dec 9 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
3291
by: bazad | last post by:
Hi, I'd like to understand consequences of Application.DoEvents call. Does it create a new thread? Thank you
6
609
by: foldface | last post by:
Hi I am doing drag and drop between controls (listview and treeview) using mouse_event. What I am after is a book/resource to explain the behaviour below. If I do the various Win32 api calls and call Application.Run, it works. I can see dragging and dropping on the screen. If I do this:
6
4299
by: Ollie Riches | last post by:
I understand the use of Application.DoEvents() to process all outstanding messages on the message queue in a winforms application if you have long running process on the UI thread. But can anyone explain to me why I need to call DoEvents when I am using a COM component that calls back to into the ..Net application? - If I don't call DoEvents after receiving a callback then sometimes no more messages are pumped, it appears that the message...
1
5965
by: RSH | last post by:
I created a new Windows Form project and I created a simple richtextbox to write to and I am looping through a simple example but obviously the screen isn't updated it only shows the first occurance. I have used Application DoEvents in the past to update the screen which works. but for some reason in this project when i use Application.DoEvents i get the error... "DoEvents() Is not a member of DTS.Application" How do I make the...
5
4579
by: james.jdunne | last post by:
System.ArgumentException: Item has already been added. Key in dictionary: "-1" Key being added: "-1" at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) at System.Collections.Hashtable.Add(Object key, Object value) at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FRegisterComponent(IMsoComponent component, MSOCRINFOSTRUCT pcrinfo, Int32& dwComponentID) at...
16
12925
by: Alan T | last post by:
I tried to use a thread to process a iterative execution of processes but afraid my thread is not thread-safe. If I am not using a thread, my main form will become 'white' when switch forth and fro between other applications. So now I tried Application.DoEvents(). But it seems does not help, my main form still displays as 'white' when switch between other application.
4
10930
by: Woo Mun Foong | last post by:
Hi, I have a DLL that is used to carry out some lengthly process. I would like to have something similar to DoEvents that can yield control back to Windows every now and then. Any ideas ? Thank You,
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.