Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.
VB.NET - How do I use Doevents() in Class Library

Answered 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 PM
    Moderator
     
     
    You need to add a reference to System.Windows.Forms.dll.
  • Tuesday, September 06, 2005 4:18 AM
     
     Answered
    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... Smile
  • Tuesday, September 06, 2005 6:43 AM
     
     
    I'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