Want to call DoEvents from library project

G

Guest

We've broken our app into various assemblies. The WinForm assembly provides
the user interface, other assemblies provide various I/O services. I'd like
to be able to call System.Windows.Forms.Application.DoEvents from within a
dll, but it isn't allowed. I don't want to link the dll to our WinForm exe
which can call DoEvents.

Is there some way to call DoEvents from within a dll?

Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

dotNETDavid,

Why can't you call DoEvents? It is a public static method on the
Application object. You should have no problem calling it.

However, whether or not you SHOULD call it, that is a different story.
If you have a long running operation, then you should really spawn it off to
another thread, and eliminate the need to have DoEvents called. There
really is little reason to call DoEvents, ever. It's a hack for those that
don't use threads to perform long operations.

Hope this helps.
 
G

Guest

Nicholas:

Calling System.Windows.Forms.Application.DoEvents(); gives the error:

<path>\Comm.cs(354): The type or namespace name 'Windows' does not exist in
the class or namespace 'System' (are you missing an assembly reference?)

when I use it in a library project.

I'm using a serial port dll that does use threading. While waiting for input
from the port I'm in a loop where I'd like to call DoEvents to allow other
applications to have more timeslices.

Thanks for the help.

Nicholas Paldino said:
dotNETDavid,

Why can't you call DoEvents? It is a public static method on the
Application object. You should have no problem calling it.

However, whether or not you SHOULD call it, that is a different story.
If you have a long running operation, then you should really spawn it off to
another thread, and eliminate the need to have DoEvents called. There
really is little reason to call DoEvents, ever. It's a hack for those that
don't use threads to perform long operations.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


dotNETDavid said:
We've broken our app into various assemblies. The WinForm assembly
provides
the user interface, other assemblies provide various I/O services. I'd
like
to be able to call System.Windows.Forms.Application.DoEvents from within a
dll, but it isn't allowed. I don't want to link the dll to our WinForm exe
which can call DoEvents.

Is there some way to call DoEvents from within a dll?

Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

dotNETDavid,

In a library project, you have to add a reference to
System.Windows.Forms, and then add the using declaration for the namespace
System.Windows.Forms at the top of the file you want to use it in.

You can't be using threading if you are waiting on the UI thread.
Rather, you should spawn those functions out to another thread and have that
thread wait. If you run this in an environment that does not have access to
the UI, then the call to DoEvents might fail, and it would defeat the
purpose of having it in a separate library.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

dotNETDavid said:
Nicholas:

Calling System.Windows.Forms.Application.DoEvents(); gives the error:

<path>\Comm.cs(354): The type or namespace name 'Windows' does not exist
in
the class or namespace 'System' (are you missing an assembly reference?)

when I use it in a library project.

I'm using a serial port dll that does use threading. While waiting for
input
from the port I'm in a loop where I'd like to call DoEvents to allow other
applications to have more timeslices.

Thanks for the help.

Nicholas Paldino said:
dotNETDavid,

Why can't you call DoEvents? It is a public static method on the
Application object. You should have no problem calling it.

However, whether or not you SHOULD call it, that is a different
story.
If you have a long running operation, then you should really spawn it off
to
another thread, and eliminate the need to have DoEvents called. There
really is little reason to call DoEvents, ever. It's a hack for those
that
don't use threads to perform long operations.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


dotNETDavid said:
We've broken our app into various assemblies. The WinForm assembly
provides
the user interface, other assemblies provide various I/O services. I'd
like
to be able to call System.Windows.Forms.Application.DoEvents from
within a
dll, but it isn't allowed. I don't want to link the dll to our WinForm
exe
which can call DoEvents.

Is there some way to call DoEvents from within a dll?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top