VB.NET - How do I use Doevents() in Class Library
-
Monday, September 05, 2005 5:47 PM
Using VB.NET 2005 - Beta 2,
I've created a Windows Form Application with a single form and several new Classes and now I am trying to separate them and make a .dll out of the custom classes.
I created a new "Class Module" project and used "Add Existing Item" to select each of the custom class.vb files.
Some of the methods attached to my custom classes take a while to run and so I had coded them interspersed with "windows.form.application.doevents()" statements.
Now that there is no form in my new project, these lines are generating errors that "Application" is not a member of "Forms".
So my question is:
How can I add a 'Doevents()' to methods in my class library?
Thanks in advance...
All Replies
-
Monday, September 05, 2005 6:25 PMModeratorYou need to add a reference to System.Windows.Forms.dll.
-
Tuesday, September 06, 2005 4:18 AM
This is one way of doing it, but it is not really the best way.
You are better off using threads to do it (and sleeping the thread to save CPU for long running tasks).
E.g.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myThread As New System.Threading.Thread(AddressOf myLongTask)
myThread.Start()
// Do something else, thread will start in its own sweet time
End Sub
Private Sub myLongTask()
Dim TaskFinished As Boolean
Do
System.Threading.Thread.CurrentThread.Sleep(0)
// Do lots of stuff
Loop Until TaskFinished = True
End Sub
And threading is a whole new world full of stuff that needs to be learnt...
-
Tuesday, September 06, 2005 6:43 AMI'm using a lot the instruction Thread now on Framework 1.1. Very simple to use and you can get more than a single task running. Pls read tha manual written by Francesco Balena (Microsoft press) in order to get more informations

