Connecting Tech Pros Worldwide Forums | Help | Site Map

DoEvents in VB.NET

Julia Beresford
Guest
 
Posts: n/a
#1: Mar 22 '06
Hi

I have a Class Library with a class in it. The class has a method that
processes a whole load of stuff. I want to be able to pause this method from
the application using this class.

In VB6 I would have had a DoEvents statement in my method. This would have
allowed the user to select 'Pause' on the user interface, I would have then
set a variable in the class 'paused = True', and I would check the value of
this variable in my method.

However with VB.NET I'm not sure this is the way to go (for a start DoEvents
isn't available from my class library).

Can someone please give me some pointers?

Many thanks

Julia Beresford

David Anton
Guest
 
Posts: n/a
#2: Mar 22 '06

re: DoEvents in VB.NET


There is an Application.DoEvents, but for this sort of scenario what you
probably want to do is kick off the long-running process on a separate thread
(don't have an example handy, but it's very easy - one line if I remember
correctly) and then you do not need the DoEvents to allow the user to click
that button - your UI will be responsive to it.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter



"Julia Beresford" wrote:
[color=blue]
> Hi
>
> I have a Class Library with a class in it. The class has a method that
> processes a whole load of stuff. I want to be able to pause this method from
> the application using this class.
>
> In VB6 I would have had a DoEvents statement in my method. This would have
> allowed the user to select 'Pause' on the user interface, I would have then
> set a variable in the class 'paused = True', and I would check the value of
> this variable in my method.
>
> However with VB.NET I'm not sure this is the way to go (for a start DoEvents
> isn't available from my class library).
>
> Can someone please give me some pointers?
>
> Many thanks
>
> Julia Beresford[/color]
Peter Macej
Guest
 
Posts: n/a
#3: Mar 22 '06

re: DoEvents in VB.NET


> However with VB.NET I'm not sure this is the way to go (for a start DoEvents[color=blue]
> isn't available from my class library).[/color]

DoEvents is shared method of Application class in VB .NET. So use
Application.DoEvents. I do it exactly as you described.

Just don't forget to add the following at the top of your code:
Imports System.Windows.Forms

and add System.Windows.Forms to your references.

--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code
Cor Ligthert [MVP]
Guest
 
Posts: n/a
#4: Mar 22 '06

re: DoEvents in VB.NET


Julia,

As David menioned is for this in VB 2005 the backgroundworker class. Which
is made to make threading easier.

http://msdn2.microsoft.com/en-us/library/8xs8549b.aspx

I hope this helps,

Cor

"Julia Beresford" <JuliaBeresford@discussions.microsoft.com> schreef in
bericht news:42062E0B-B282-4899-8197-7C5DC62BE2D0@microsoft.com...[color=blue]
> Hi
>
> I have a Class Library with a class in it. The class has a method that
> processes a whole load of stuff. I want to be able to pause this method
> from
> the application using this class.
>
> In VB6 I would have had a DoEvents statement in my method. This would
> have
> allowed the user to select 'Pause' on the user interface, I would have
> then
> set a variable in the class 'paused = True', and I would check the value
> of
> this variable in my method.
>
> However with VB.NET I'm not sure this is the way to go (for a start
> DoEvents
> isn't available from my class library).
>
> Can someone please give me some pointers?
>
> Many thanks
>
> Julia Beresford[/color]


Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#5: Mar 22 '06

re: DoEvents in VB.NET


"Julia Beresford" <JuliaBeresford@discussions.microsoft.com> schrieb:[color=blue]
> I have a Class Library with a class in it. The class has a method that
> processes a whole load of stuff. I want to be able to pause this method
> from
> the application using this class.
>
> In VB6 I would have had a DoEvents statement in my method. This would
> have
> allowed the user to select 'Pause' on the user interface, I would have
> then
> set a variable in the class 'paused = True', and I would check the value
> of
> this variable in my method.
>
> However with VB.NET I'm not sure this is the way to go (for a start
> DoEvents
> isn't available from my class library).[/color]

Does your application contain a graphical user interface? If it does, you
may want to use 'Application.DoEvents', or multithreading +
'Control.Invoke', or .NET 2.0's BackgroundWorker component. However, I
suggest to decouple algorithms from the user interface and start blocking
operations in their own threads, which is possible using BackgroundWorker or
the 'Thread' class directly.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Carlos J. Quintero [VB MVP]
Guest
 
Posts: n/a
#6: Mar 23 '06

re: DoEvents in VB.NET


Hi Julia,

There is a System.Windows.Forms.Application.DoEvents, but you may want to
consider threading. Here you have some resources about asynchronous
operations for .NET 1.x (there is a new BackgroundWorker class in .NET 2.0):

http://www.mztools.com/resources_net...nousOperations

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com


"Julia Beresford" <JuliaBeresford@discussions.microsoft.com> escribió en el
mensaje news:42062E0B-B282-4899-8197-7C5DC62BE2D0@microsoft.com...[color=blue]
> Hi
>
> I have a Class Library with a class in it. The class has a method that
> processes a whole load of stuff. I want to be able to pause this method
> from
> the application using this class.
>
> In VB6 I would have had a DoEvents statement in my method. This would
> have
> allowed the user to select 'Pause' on the user interface, I would have
> then
> set a variable in the class 'paused = True', and I would check the value
> of
> this variable in my method.
>
> However with VB.NET I'm not sure this is the way to go (for a start
> DoEvents
> isn't available from my class library).
>
> Can someone please give me some pointers?
>
> Many thanks
>
> Julia Beresford[/color]


Closed Thread